Welcome Guest, Not a member yet? Register   Sign In
Accessing variables in controllers and views
#5

[eluser]Fationably Late[/eluser]
I think Aken was trying to say that you are assigning $this->config->item() to an unnecessary variable. Since you are immediately passing that value into $this->data, then why don't you just do this:
Code:
$this->data['cms_template'] = $this->config->item('cms_template') ;
and bypass the variable?

But to answer your question, if the config item 'cms_template' is going to be global, or at least global in any controller that extends MY_Controller, why don't you put that assignment in the __construct of MY_Controller. Then you're keeping it DRY and you will have access to it (as well as $this->data) from any controller that extends it. But be sure to add a public $data to MY_Controller.

Code:
class MY_Controller extends CI_Controller {
    public $data;
    public function __contruct(){
        parent::__construct();
        $this->data['cms_template'] = $this->config->item('cms_template') ;
    }
}

Also, you'll never have to redeclare $data again either.


Messages In This Thread
Accessing variables in controllers and views - by El Forum - 01-09-2013, 01:21 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 02:33 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 02:36 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 02:43 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 03:00 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 03:21 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 03:32 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 03:40 PM
Accessing variables in controllers and views - by El Forum - 01-09-2013, 08:48 PM
Accessing variables in controllers and views - by El Forum - 01-10-2013, 05:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB