CodeIgniter Forums
login check logic - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: login check logic (/showthread.php?tid=54279)



login check logic - El Forum - 08-31-2012

[eluser]murichej[/eluser]
hi

i'm working on some project where user logins. i need to check if user is logined in all the controllers. it's a little bit silly to copy/paste code for checking session to all controllers. do you suggest any better way for checking if user is logined?


login check logic - El Forum - 08-31-2012

[eluser]rip_pit[/eluser]
sure, look at
Extending Core Class @ http://ellislab.com/codeigniter/user-guide/general/core_classes.html
tutorial here : http://codeigniter.tv/a-10/Extending-the-core-MY_Controller-and-beyond

In short MY_controller.php will become the mother of all your other controllers.
then it's used to share codes/functions to your other controllers/pages without need of copying/pasting code/functions.

It's easy and clean


login check logic - El Forum - 09-01-2012

[eluser]murichej[/eluser]
that's great, thanks!


login check logic - El Forum - 09-01-2012

[eluser]murichej[/eluser]
i have one more question. i created public variable in MY_Controller but i can't access it in controllers extending MY_Controller. any idea?

edit: solved. i was using $this->$variable instead of $this->variable Big Grin


login check logic - El Forum - 09-02-2012

[eluser]rip_pit[/eluser]
glad that it helped !