Welcome Guest, Not a member yet? Register   Sign In
"Security interceptor" and interceptors in general
#5

[eluser]mddd[/eluser]
Once variables are loaded in one view, they are available in all subsequent views. So that is not the problem.

I understand that $data['menu'] is something you want loaded in every controller. That's why you put it in the MY_Controller class.
But you probably have a index() method in your controllers. Like Users has an index method, right? That means it overwrites the index() you made in MY_Controller. And so, the $data['menu'] is still not set! If you want $data to "automatically" contain information, you would have to do something like
Code:
class MY_Controller extends Controller {

    var $data = array();
    
    function MY_Controller()
    {
        parent::Controller();    
        $this->data['menu'] = $this->Menu_model->get();
    }
}

And in the Controller:
Code:
class Users extends MY_Controller {

    function Users()
    {
        parent::MY_Controller();
    }

    function index()
    {
       // here you add the other stuff you need in this controller/view
       $this->data['userdata'] = get_some_user_data_to_show();
       $this->load->view('myview', $this->data);
  
       // now, you have $menu in the view (which was set in the MY_Controller)
       // and also $userdata which you set specifically in this controller
    }
}


Messages In This Thread
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 05:34 AM
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 05:49 AM
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 07:11 AM
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 07:30 AM
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 07:46 AM
"Security interceptor" and interceptors in general - by El Forum - 08-11-2010, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB