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

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Having database access in 3rd party lib (/showthread.php?tid=61626)



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