Welcome Guest, Not a member yet? Register   Sign In
Accessing MY_Controller vars from hook
#1

[eluser]senic[/eluser]
Hi,

i've been trying to make CI work for my but i stumbled accross a little issue.

I extended the Controller to get a few things like login covered and i'm also using a small template system to have some support for partials.

So, i feed the $template var with the always-there stuff and add the dynamic things from the News controller. I could do the actual rendering of the page itself in the News controller of course, but why write the same line in every controller i need over and over again. Wink

So i tried to put the actual rendering in a post_controller hook (Template class below), but the problem is that it seems like the $template var is not accessible there or to be more clear, the dynamic things getting added from the News controller are missing. Only the things added in the constructor of MY_Controller() are there, so it looks like it gets overwritten.

Any idea how to make the MY_Controller variable available in a hook just how they are available in a regular controller?

MY_Controller lib
Code:
class MY_Controller extends Controller  {
    
    var $template = array();
    
    function MY_Controller() {
        parent::Controller();
        $this->loginbox();
        $this->createmenubar();
    }

Controller
Code:
class News extends MY_Controller {
    
    function News() {
        parent::MY_Controller();
    }

    function index()
    {
        [... feeding $data ...]
        $this->template['content'] = $this->load->view('content_news', $data, TRUE);
    }
}

Hook
Code:
class Template extends MY_Controller {
    
    function Template() {
        parent::MY_Controller();
    }

    function index()
    {
        $this->load->view('template', $this->template);
    }
}


Messages In This Thread
Accessing MY_Controller vars from hook - by El Forum - 03-10-2010, 06:43 PM
Accessing MY_Controller vars from hook - by El Forum - 03-11-2010, 08:46 AM
Accessing MY_Controller vars from hook - by El Forum - 03-12-2010, 07:07 AM
Accessing MY_Controller vars from hook - by El Forum - 03-19-2010, 04:53 AM
Accessing MY_Controller vars from hook - by El Forum - 03-19-2010, 07:17 AM
Accessing MY_Controller vars from hook - by El Forum - 03-25-2010, 07:59 AM
Accessing MY_Controller vars from hook - by El Forum - 03-25-2010, 09:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB