CodeIgniter Forums
Having database access in 3rd party lib - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Having database access in 3rd party lib (/thread-61626.html)



Having database access in 3rd party lib - Hamed - 05-01-2015

Hello, I have a 3trd party lib.
Now I want to use database in that.
How can I do this job?


RE: Having database access in 3rd party lib - Urastor - 05-06-2015

Look here: http://www.codeigniter.com/userguide3/general/creating_libraries.html#utilizing-codeigniter-resources-within-your-library

Soo.. for example:


PHP Code:
class extLib3 {
  
    
private $ci;

    public function __construct() 
    {
        //Getting CI instance (the =& is important and not a typo, because you want the original, not a copy (assigning by reference))
        $this->ci =& get_instance();

        //Load database
        $this->ci->load->database();
    }