Welcome Guest, Not a member yet? Register   Sign In
couldn't create own library
#5

To create a library is very simple with CI. First you have to create a File with your Classname in your /application/library folder like

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Rufnex {

    function 
__construct($params)
    {
        
$this->param $params['test'];
        
$this->ci =& get_instance();
    }

    public function 
hello()
    {
        echo 
"hello world";
    }

    public function 
load()
    {
        
$this->ci->load->library('calendar');
        echo 
$this->ci->calendar->generate();
    }

    public function 
param($param)
    {
        echo 
"content of my param: ".$param;
        echo 
"<br />";
        echo 
"content of my class param: ".$this->param;
    }
    


Then you can call your Class in you controller like this

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends MY_Controller {

    function 
__construct()
    {
        
parent::__construct();
    }

    public function 
index()
    {
        
$this->load->library('rufnex', array('test' => 123));
        
$this->rufnex->hello();
        
$this->rufnex->load();
        
$this->rufnex->param('test');
    }


As you see, there is no magic ;o) For further details please refer to the documentaion at http://www.codeigniter.com/user_guide/ge...aries.html

Reply


Messages In This Thread
couldn't create own library - by kavy - 01-20-2015, 10:25 PM
RE: couldn't create own library - by Avenirer - 01-21-2015, 01:55 AM
RE: couldn't create own library - by InsiteFX - 01-21-2015, 05:30 AM
RE: couldn't create own library - by RobertSF - 01-22-2015, 06:35 PM
RE: couldn't create own library - by Rufnex - 01-23-2015, 01:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB