• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

I have seen other posts relating to similar problems but none of them got an answer that works.

I am a beginner with codeigniter, using version 2.0.2 with php 5.3.

I am testing with a controller called start.php and the code is:


class Start extends CI_Controller
    var $base;
    function _construct()
        $this->base = $this->config->item('base_url');
    function hello()
        $data['base'] = $this->base;
        print_r ($data);

When I go to the hello function in the browser, the print_r function shows that $data is empty (like this: Array ( [base] => ) ). Why is the value set for $this->base in the constructor not available in the hello method? I have now spent about 8 hours on this one issue without success.

__construct, not _construct

I don't believe it! All those hours and it was that simple. All OK now!

I checked the User Guide yet again and under Controllers/Class Constructors there is no mention that it is a double underscore and it's not obvious to my 70 year old eyes.

Thank you so much, noctrum

Constructors are covered more thoroughly on php.net Wink

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.