Welcome Guest, Not a member yet? Register   Sign In
Load a function when after the controller
#1

[eluser]Emanuel01[/eluser]
Hello ,
I want to make a header - footer system and i`ve make this little plan :
I will extend my controllers with a MY_Controller library where i have 2 function : header that will be used before the controller and footer that need to be used after the controller .
Now i don`t know how to make the footer to be executed after the controller . Maybe with the php function __destruct ?
P.S. i don`t want to write at the end of every controller the function maybe exist another solution

Thx for the help and sorry for my english .
#2

[eluser]Pascal Kriete[/eluser]
Using __destruct does not work very well because you can no longer use the loader, which means you would have to preload the footer and keep it in memory while the controller is executed.

I usually do this with a library (i.e use the library to handle view loading instead of calling load->view directly), but another solution might be to add an _output function to your parent class. That will break a few other things though (most notably caching).
#3

[eluser]Emanuel01[/eluser]
I will use your method with view library . Verry simple Smile
Thx Pascal Kriete
#4

[eluser]zovar[/eluser]
Yes, it's a very old topic, but could someone give me a hint on how to use library to load views?
I wanted to use _destruct method but since it doesn't always work I am looking for another solution to load my footer view for every method.
#5

[eluser]jedd[/eluser]
[quote author="zovar" date="1236802884"]Yes, it's a very old topic, but could someone give me a hint on how to use library to load views? [/quote]

I keep pointing people back to [url="http://ellislab.com/forums/viewthread/106945/"]this thread about loading a main view with vars containing sub-views[/url] as I think it's the most elegant way to go about this.

If you want to create data (but not display it at the time) then the MY_controller thing works well, I think.

I'd avoid the _destruct and _output approaches - they seem to have a significant cost and don't offer anything above the above two approaches (separately or combined) IMO.

Quote:I wanted to use _destruct method but since it doesn't always work I am looking for another solution to load my footer view for every method.

Do you mean every controller, or every method within a particular controller? If it's every method just make a helper and load that in the constructor for the class.




Theme © iAndrew 2016 - Forum software by © MyBB