Need tips about authentication check (cookies) |
What is the most common and robust auth check pattern in CI?
I personally see two ways: 1) insert check routine into a hook-function ('pre_controller' or 'post_controller_constructor' ?) - one for all controllers - nice 2) write it in __construct() directly, but it forces to duplicate code a lot, for each controller. bad.. I tried 1st way but got this: PHP Code: $hook['pre_controller'] = function () It seems that $this->input is absent in function's scope. Maybe I should create standalone class? or entirely different approach? Please nudge me in a right direction.
Create a MY_Controller and do your checks in it, then extend all your other controller's from your MY_Controller.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Besides the fact that you want to check a user id from a cookie i think you are on the right path.
Try the following: in your config/hooks.php PHP Code: $hook['pre_controller'][] = array( and create a File named AppCookieValidator.php in the application/hooks/ directory and do something like this PHP Code: class AppCookieValidator (11-03-2015, 04:45 AM)sintakonte Wrote: Tried it. Should be $hook['post_controller_constructor'] otherwise get_instance() returns NULL. |
Welcome Guest, Not a member yet? Register Sign In |