Calling 2 controllers? |
[eluser]FinalFrag[/eluser]
I'm currently working on my website and I got the following problem: I have a header.php that is included at the top of every view. I also have a footer.php that is included at the bottom of every view. So basicly it comes down to this in my view files: Code: $this->load->view('header'); My menu is in the footer.php file because it needs to be parsed after the content does. So the footer.php file looks like this: Code: // close some open divs from the content The problem is as follows: In this menu I need information from the database. However, when I use $this->load->model('menu') it doesn't work (figures, as I am in a view, not a controller). How can I solve this? Should I make a call to another controller (if that is at all possible) or am I doing something else wrong. Thnx in advance...
[eluser]FinalFrag[/eluser]
Could you give me a bit more info/how-to on that subject? I'm still pretty new to CodeIgniter...
[eluser]Seppo[/eluser]
Sure. To set up a hook, take a look here, it's quite simple. Then you should have a function that will be called on every request, something like this Code: function myhook() Then, on any view loaded you will have $menu set with the result from the controller.
[eluser]wiredesignz[/eluser]
Modular Extensions would be a better choice than using hooks. See my signature.
[eluser]zdknudsen[/eluser]
You could also try and put this experimental library of mine in your /application/libraries/ directory and simply call your other controller through Code: $this->load->controller('segment1/segment2/etc'); I haven't tested it very much, though. http://www.filepanda.com/file/5wvzss2zkkp5/ Edit: Actually, you should be able to work out your problem without any fancy workarounds. First of all, why are you require_once-ing your menu.php? What kind of file is it? And why does the menu need to be parsed after the content? Usually you would probably use either a model or library to parse your menu and save it to a variable that you pass to the view.
[eluser]gtech[/eluser]
can't you just load the model in the constructor of every controller?
[eluser]FinalFrag[/eluser]
Autoloading it every time is a bit to much work. Cause I just know I will forget some day :p Currently I solved it like this (menu.php): Code: if (!defined('BASEPATH')) exit('No direct script access allowed'); I'm looking for the 'good' way to do something like this, but it shouldn't be more code than this, because that would be kind of stupid |
Welcome Guest, Not a member yet? Register Sign In |