Using sessions and setting variables in pre_controller hook |
[eluser]FinalFrag[/eluser]
I have a website that has a menu at the top. The items of this menu are in a database. I could load a model in all of my controllers, but I rather have a piece of common code somewhere so that I don't have to think about loading the model and calling the getMenuItems() function myself. From the userguide, the only possible solution I see are hooks, a pre_controller one to be exact. I've been fooling around with this, but I'm stuck with 2 problems: 1) How do I pass the session to a pre_controller hook 2) How do I set variables that I can use later on I need to have access to the session because the menu when you are not logged in is different from the one you get when you are. The need to set a variable is to call the $header_menu variable in my view. Thnx in advance
[eluser]Phil Sturgeon[/eluser]
I used to try doing this with pre_controller hooks but came across a better way posted here by a user I forget. The exact same effect can be done via extending the controller class. Its a little less beautiful but it works a treat. Make MY_Controller.php and inside it do code such as: Code: <?php Then this $this->data->menu work throughout your controller and can be passed to views as well.
[eluser]Phil Sturgeon[/eluser]
Not the post I was talking about, but this one explains it: http://ellislab.com/forums/viewthread/89875/ |
Welcome Guest, Not a member yet? Register Sign In |