Help: Where to put my controller function logged_in() |
[eluser]Wondering Coder[/eluser]
I have this function in almost all of my controllers, this prohibit any unauthorized user to access a certain page in my site. Code: function is_logged_in() But what I would like to do is just call this function logged_in in just one controller and not doing a copy-paste thing. Is this the part where I would need to extend my controller? Haven't really tried it though. BTW - It's just been 3 months since I learned using CI.
[eluser]WanWizard[/eluser]
Read up on base controllers. Phil Sturgeon wrote a good article about it. In short, create an Public_Controller, Private_Controller and maybe an Admin_Controller. All extend CI_Controller. All your controllers that need to be accessable without authentication will extend Public_Controller, all controllers that require you to be logged in extend Private_Controller, which checks the logged in state. And you may have other base controller for specific functions. You also use these base controllers to house all methods and properties that should be available to all your controllers, so you'll have to code them only once.
[eluser]Wondering Coder[/eluser]
thnx WanWizard, I'm reading it right now. Actually I have 2 module site: Admin Module and Private Module and as for my public site maybe its just for my registration and login page.. I'm getting the picture now. I'm getting the picture now. Also does this article up to date? Because I'm using CI 2.0.
[eluser]Wondering Coder[/eluser]
follow up question WanWizard, Code: application/libraries/Admin_Controller.php
[eluser]WanWizard[/eluser]
CI doesn't have any class autoloading capabilities, so in theory you can put them where you want them. You have to load them manually before the controller gets loaded. As of CI 2.0, I would suggest putting them in core, together with MY_Controller. For CI 1.7.x, libraries is the place to store them.
[eluser]Wondering Coder[/eluser]
ahh, ok. Its just that based from what I understand all extended library in system/libraries had to be put in application/libraries. hmmn. Anyway thanks a many WanWizard ^_^. |
Welcome Guest, Not a member yet? Register Sign In |