[eluser]Zehee[/eluser]
[quote author="SpaceCoder" date="1291661392"][quote author="Zehee" date="1291654683"]Use the Form_validation class in controller is a fine choice.
Meanwhile, do a simple check in model is necessary, my personal view.[/quote]
How check the $this->session->userdate('logged_id') flag with Form_validator?[/quote]
I put this function
Code:
function isLogin()
{
$CI =& get_instance();
$session_key = $CI->session->userdata('session_key');
return (!empty($session_key));
}
in my current_helper.php ( I added this helper file).
And in MY_Controller.php add this method:
Code:
protected function _checkLogin($redirect = 'login')
{
if (!isLogin())
{
redirect($redirect);
}
else
{
return true;
}
}
Then in Controllers:
Code:
class Comment extends MY_Controller {
function __construct()
{
parent::__construct();
}
function add()
{
$this->_checkLogin();
...
}
...
}
By this way, when you want to check login somewhere in your website, just call the methd '$this->_checkLogin()' in your controller. Sometimes, your can put this in __construct() when you need.
The data in session always use the similar way.
The data post/get form view use Form_validation class