Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] $this->load->vars from super controller?
#1

[eluser]Prophet[/eluser]
Hi all. I have a method in MY_Controller which is used extensively throughout other child controllers. A problem I have come across is that if I call $this->load->vars() in MY_Controller, the child controllers don't seem to inherit the variables? Example:
Code:
class MY_Controller extends Controller
{
    public function my_function()
    {
        $vars['title'] = 'Title';
        $vars['greeting'] = 'Hello';
        $this->load->vars($vars);
    }
}
Code:
class Welcome extends MY_Controller
{
    public function index()
    {
        $this->my_function();
        $this->load->view('welcome');
    }
}

I expected the 'welcome' view to inherit $title and $greeting... But it doesn't. Is there any way I can get this to function as I expect? Or will I have to do something like:
Code:
class MY_Controller extends Controller
{
    public function my_function()
    {
        $vars['title'] = 'Title';
        $vars['greeting'] = 'Hello';

        return $vars;
    }
}
Code:
class Welcome extends MY_Controller
{
    public function index()
    {
        $vars = $this->my_function();
        $this->load->vars($vars);
        $this->load->view('welcome');
    }
}
#2

[eluser]Prophet[/eluser]
Solved it on my own. The issue was with my code - not CodeIgniter... Typical Smile




Theme © iAndrew 2016 - Forum software by © MyBB