I have a problem I tried this codes:
enabled hooks in application/config/config.php
$config['enable_hooks'] = TRUE;
added library in applciation/config/autoload.php
$autoload['libraries'] = array('smarty','session');
code in application/config/hooks.php:
$hook['post_controller_constructor'][] = array(
'class' => 'App_auth',
'function' => 'index',
'filename' => 'App_auth.php',
'filepath' => 'controllers',
'params' => ''
);
code in application/controller/App_auth.php :
class Auth_module
{
private $CI;
function Auth_module()
{
$this->CI = &get_instance();
}
function index()
{
echo'aaaaaaaa';exit(0);
if ($this->CI->session->userdata('user_id') == "" ) // If no session found redirect to login page.
{
redirect(site_url('login'));
}
}
}
sample code in application/libraries/Session.php:
Please check this site for the codehttp://codeigniter.com/user_guide/libraries/sessions.html
Replaced function userdata($item) with this code:
function userdata($item)
{
echo'bbbb';exit;
return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item];
}
I don't have any idea what could be the solution as I already other codes. Please enlighten me with this. THANKS! :)
Why is that echo'aaaa'; and echo 'bbbb'; are not showing? Also is there wrong with my code?
enable hooks in config
$config[‘enable_hooks’] = TRUE;
Your Auth_module
should contain
function Auth_module()
{
$this->CI = &get_instance();
}