Error redirect from hook to another controller |
I want redirect user in login page if is not logged
my hook HK_Login.php inside application/hooks Code: <?php my controller Secure.php inside application/controllers Code: <?php My .htaccess Code: DirectoryIndex index.php A part of my config.php Code: $config['index_page'] = ''; autoload Code: $autoload['helper'] = array('url', 'custom'); hook config Code: $hook['post_controller_constructor'][] = array( This is my routes.php Code: $route['default_controller'] = 'dashboard'; The result is : Code: Not Found Why give me this error?
post_controller_constructor will run AFTER the controller runs, hence "post" in the name. Not the place to be checking for authentication since it will check auth after the controller runs, allowing the person to do whatever they want.
You also really don't need to use a hook for this. Just create a base controller, MY_Controller, and have all of your other controllers that require auth checking extend that instead of CI_Controller. I suspect your real problem though is the use of $this->CI->uri->segment(1) in your redirect: redirect($this->CI->uri->segment(1) . '/secure/login'); It appears that segment(1) is "web", so it redirects to web/secure/login, but you don't have a route for that. Your route is just "secure/login". Probably just remove the reference to segment(1) there. /application/core/MY_Controller.php PHP Code: class MY_Controller extends CI_Controller { Then for all of your other controllers that require auth just extend MY_Controller... /application/controllers/Other_class.php PHP Code: class Other_class extends MY_Controller { Some reading: http://www.codeigniter.com/user_guide/ge...core-class
Because you don't have /web/secure/login. It seems you don't have `web` controller.
> The requested URL /web/secure/login was not found on this server. |
Welcome Guest, Not a member yet? Register Sign In |