Welcome Guest, Not a member yet? Register   Sign In
Making code run on all pages
#1

[eluser]oste15[/eluser]
Hello,

I am wondering what the best way to run code on each page without having to add it into each controller.

For example if you want to check if a user is logged in on each page, and send them to the login page if they are not logged in. You could add the following to each controller, but I think it would be best to just write this once and run it on each page no matter what.

Code:
if(!$user){
//send to login
}

Thanks for clearing this up for me.
#2

[eluser]gh0st[/eluser]
Put it in MY_Controller. Then you extend MY_Controller. Do a search on the topic of MY_Controller both here and Google and you will get some good pointers.
#3

[eluser]oste15[/eluser]
So when I create this MY_Controller class I will have to extend that class rather than Controller in each of my controllers?
#4

[eluser]laytone[/eluser]
Yes




Theme © iAndrew 2016 - Forum software by © MyBB