CodeIgniter Forums
Why $CI =& get_instance(); in each function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Why $CI =& get_instance(); in each function (/thread-46611.html)



Why $CI =& get_instance(); in each function - El Forum - 11-08-2011

[eluser]TerryT[/eluser]
I have a library where I call this in the constructor:


Code:
class Mypdf extends TCPDF
function __construct()    {
  parent::__construct();  
    $CI =& get_instance();
    $CI->load->library('session');
    $CI->load->library('pdf');

I also have these methods:

Code:
public function newpdf($title, $subject, $report_name)
public function body_project_listing()

To access sessions in either of the functions, I have to call:

Code:
$CI =& get_instance();
    $CI->load->library('session');
    $CI->load->library('pdf');
[/code]

in each function. Can anyone let me know why I can't just call it in the parent::__construct()? Thanks.