Extending Controller & _output() |
[eluser]Unknown[/eluser]
I'm new to CI. I want to extend the main Controller so that a function will be included in all of my controllers. My problem is the view within views. I've found a view library that seems to do the job i want. But I don't want to have to keep doing Code: $this->view->part('left_column', 'left_column.php'); // (file extensions added for clarity) in every controller. So I wanted to put a _output function in every controller by default. If I put the _output function in every controller, it works fine. But again, it's having to put the same code in every page. Which is where extending the base controller would come in. However, when I tried to extend the controller using Code: <?php Quote:Fatal error: Class 'CI_Controller' not found in C:\Documents and Settings\Luke\My Documents\Web Sites\dating\index\system\application\libraries\MY_Controller.php on line 3When I change "CI_Controller" to "Controller" it works fine. But it doesn't call the _output function. I suppose I could just create a normal output function and include it as a helper or something and then pass the controller through as an object, but it's not very elegant. My end plan is to run the controller as normal and then load a single particular view (eg login/register page). Once the view is loaded and processed via normal methods, the _output function takes over and inserts the view loaded into the correct place in a 'global' template/view (eg header tags, navigation bars). Anyone have any pointers on how to do this?
[eluser]Mirage[/eluser]
There's probably a couple of ways to work this. The controller, model and database classes are not officially supported for the Core Class extension. An option you do have is to include your own controller subclass: Code: <?php Code: <?php However, I don't think subclassing the controller is the best solution for your problem, because the problem isn't controller related but rather view related as you stated. I therefore recommed you use that view library from coolfactor. You could subclass that and then always add the default parts to it in it's constructor. This gives you the option to still override them from the controller or a specific controllers function. Still, I'd personally opt to set the 'parts' in each controllers constructor. It's a default thing that can be overridden in the action methods. Cheers! |
Welcome Guest, Not a member yet? Register Sign In |