Can _output function within a controller load views? |
[eluser]inktri[/eluser]
Code: function _output($output) for some reason only the $output (and not the header/footer) is being outputted for the controller. If I were to move the $this->load->view('header_view') function into the controller's constructor, the header loads properly. Anybody know what's wrong? I've also tried Code: echo $this->load->view('header_view');
[eluser]gtech[/eluser]
*** [edit] THIS IS RUBBISH IGNORE i forgot the _ouput function was 'special' [/edit]
[eluser]christian.schorn[/eluser]
The _output function is called after the controller-method is run ("links" in this case) and the final processing is done, so the views will be loaded, but never displayed. One possibility is, if you have header/footer files without variables to include them: Code: function _output($output) But it looks to me as if this will break whith caching turned on! @gtech: what you did, was forcing the _output routine to be called twice, once by the controller and then once again by the framework, with no effect the second time.
[eluser]gtech[/eluser]
@Christian yep I forgot _output() was a function to render the final output.. so appologies, I have fixed my code below using your suggestions. Code: <?php
[eluser]christian.schorn[/eluser]
I just tested it ... this will break when caching is turned on. When a valid cache-file is found, CI will call CI_Output::_display_cache and exit before the controller class is loaded, so there is no chance to call _output.
[eluser]gtech[/eluser]
Yes your right I tested your theory, I dont think there has been a bug logged about this one.. you might want to mention it in the bug forum.. A simple fix might be to put that "caching has to be turned off for the _output function to work" in the documentation. I have a feeling that inktri might of not called the $this->output->set_output(<WHATEVER>); function and that is why there is no output at all. [url="http://ellislab.com/forums/viewthread/76960/"]http://ellislab.com/forums/viewthread/76960/[/url] link to same problem about caching with no replys
[eluser]inktri[/eluser]
is there a way to just call a line after every function in a controller? i'll just rely on the constructor for the header, but don't know how to go about loading the footer view
[eluser]gtech[/eluser]
you could create a library: system/libraries/template.php Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); system/controllers/home.php Code: class Home extends Controller [url="http://ellislab.com/forums/viewthread/78151/"]http://ellislab.com/forums/viewthread/78151/[/url]
[eluser]christian.schorn[/eluser]
Actually I think this is not a bug - if you go through the routes to find the controller, instantiate it (and maybe load a lot of libraries via the controllers constructor) you lose very much of the effectiveness of CIs caching as it is. In this case it would be enough to make a special method, either in a MY_Controller, or as you need it. Example: Code: class MY_Controller extends Controller Then there are hooks ... you could write your own cache_override hook ... but that's a little much just for layout purposes, IMO. Edit: Or you could do it via a library, as gtech posted, while I was writing this ...
[eluser]gtech[/eluser]
Ive just edited the code above and tested it to ensure it works, Christians method looks like an equally valid approach. so go with whatever you feel comfortable with. |
Welcome Guest, Not a member yet? Register Sign In |