Welcome Guest, Not a member yet? Register   Sign In
Variables
#1

[eluser]Perkin5[/eluser]
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:

Code:
<?php  

class Start extends CI_Controller
{
    var $base;
    function _construct()
    {
        parent::_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.
#2

[eluser]danmontgomery[/eluser]
__construct, not _construct
#3

[eluser]Perkin5[/eluser]
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
#4

[eluser]danmontgomery[/eluser]
Constructors are covered more thoroughly on php.net Wink




Theme © iAndrew 2016 - Forum software by © MyBB