i’m having trouble with a simple hook in CI version 1.7.3.
i setted up a [pre_controller] hook in config hook.php file and the hook code is:
class Cookie {
function remember_me(){
$CI =& get_instance();
if($CI->input->cookie('remember_me_id',true)){
$CI->load->model('user');
$user = $CI->user->populateById($id = $CI->input->cookie('remember_me_id',true));
if($user){
if($CI->input->cookie('remember_me_token',true) == md5($user->email.$user->password)){
$CI->bootstrap->setUserSession($user);
}
}
}
}
}
//end class
the hook is loaded and executed but it doesn’t load the input library cause it return error:
Call to a member function cookie() on a non-object
how can it be possible? could be possible that Input library is loaded after hooks is executed? :O
… cause in controllers,views and models input library works with no errors :/
Correct, the input class is not loaded at the
pre_controllerhook. You need to use thepost_controller_constructorhook.If that isn’t early enough for you you will need to override the CI_Controller class itself.