I have a controller "user" in my codeigniter application. This controller has a function called logged_user_only()
:
public function logged_user_only()
{
$is_logged = $this -> is_logged();
if( $is_logged === FALSE)
{
redirect('user/login_form');
}
}
As this function calls another function called is_logged()
, which just checks if the session is set, if yes it returns true, else returns false.
Now if i place this function in the begining of any function within same controller, it will check if the user is not logged, it will redirect to login_form
otherwise continue. This works fine.
For example,
public function show_home()
{
$this -> logged_user_only();
$this->load->view('show_home_view');
}
Now I would like to call this logged_user_only()
function in a function of another controller to check if the user is logged in or not?
PS. If this can not be done, or is not recommended, where should i place this function to access in multiple controllers? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…