Welcome Guest, Not a member yet? Register   Sign In
how to create simple library
#1

[eluser]my9006ci[/eluser]
Hi,

i have questions,
1. how to create a simple library?
2. how to used model, config, in my library?
3. how to used the library in my controller?
please help me

thanks
#2

[eluser]pickupman[/eluser]
Simple...read the user guide.

Naming conventions for libraries works the same for controllers and models, first letter capitalized, the rest lowercase. You can use any 3rd party php classes and rename to the right pattern, and you can use CI's syntax.
In order to use CI syntax you need to declare the CI global instance.
Code:
class Your_class {
  
  var $ci; //Declare CI instance

  public function __construct(){
      $this->ci =& get_instance(); //Set CI instance

      $this->ci->load->model('my_model');   //load a model
  }

  public function my_first_method(){
      
      $this->ci->config->item('some_item'); //access config values
      
      $this->ci->my_model->model_method();  //access method in model
  }

}

//In controller
$this->load->library('your_class');
$this->your_class->my_first_method();
#3

[eluser]mashary[/eluser]
wow this is very usefull, i can create my own now!

thanks




Theme © iAndrew 2016 - Forum software by © MyBB