CodeIgniter Forums
how to create simple library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to create simple library (/showthread.php?tid=30519)



how to create simple library - El Forum - 05-17-2010

[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


how to create simple library - El Forum - 05-18-2010

[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();



how to create simple library - El Forum - 06-07-2010

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

thanks