Welcome Guest, Not a member yet? Register   Sign In
Declare variable in constructor

How can I declare a variable in the constructor of a controller so that this variable is available in the dozens of functions in this controller? I'm not interested in passing it through to a view or model.

    function __construct()
                //none of the following work
        $global['uid'] = $this->session->userdata('id');

                $this->uid = $this->session->userdata('id');
                $uid = $this->session->userdata('id');


$this->uid works. Although, hardly necessary since $this->session->userdata is available as well. If it's not working, you're doing something else wrong.

Sorry, problem solved! Stupid syntax error.

Could you post what worked for people who are trying to work out similar problems?

This works:

$this->uid = $this->session->userdata('id');

Theme © iAndrew 2016 - Forum software by © MyBB