Parse template once |
[eluser]xinq88[/eluser]
Hi all, here I am, with another problem for you guys . Hope you can help me. I've got the following function of every controller (implemented in the controller class): Code: private function ParseTemplate() In other controllers I set the data and the views. So I've got multiple functions, all the functions call the ParseTemplate method at the end of the function. When I use only one function for a view, this works great, but when I've the following code: Code: public function FunctionOne($cat_id = 0) In this case, the template will be parsed twice, because the two functions but call the ParseTemplate method. I can't just delete the ParseTemplate function in 'FunctionTwo' because $someCondition is not always TRUE. So my question: How can I fix this problem, is there somehow a way of calling a method always at the end of the controller, or something like that? I hope it's clear to you guys. Thank you all for your time!
[eluser]Dready[/eluser]
Hello, perhaps add a flag to tell FunctionOne if it have to call parseTemplate ? A thing like : Code: public function FunctionOne($cat_id = 0)
[eluser]xinq88[/eluser]
Yeah, that's definitely a solution. I just hope there is some function which is called every time a controller is done. So basically a sort of 'ControllerEnd' function.
[eluser]Dready[/eluser]
I follow your opinion: CI is missing a "ControllerStart" and "ControllerEnd" function, beside PHP's constructors and destructors.
[eluser]xinq88[/eluser]
So basically what you're saying is that I've to use flags for these problems?
[eluser]Dready[/eluser]
Ci does not provide the type of function you are needing. Perhaps you can test with PHP destructors if you're using PHP5, or use flags.
[eluser]xwero[/eluser]
You can use the post_controller hook to do things like this. A way to use it is to autoload a rendering library that receives all the data and templates that need to be displayed and in the post_controller hook you put the rendering method. |
Welcome Guest, Not a member yet? Register Sign In |