Welcome Guest, Not a member yet? Register   Sign In
Load a controller into another controller
#2

If you have a controller for login, I'm sure you are using a session variable to "remember" if a user is logged in. Or a library that is active accross all controllers to check if a user is logged in.
Your FB like controller also needs to check this. If the user is not logged in, store the current url in a session variable, redirect to the login page, and after a succesful login, redirect to the url that was stored in the session.

I have this concept in MY_Controller.php (in application/core).
PHP Code:
protected function force_login()

 if (! 
$this->ion_auth->logged_in() ) {
 
$this->session->set_userdata('redirect_after_login',current_url());
 
redirect('/login');
 exit;
 } 



In every controller method that is only accessible for logged in users, I have this line:
PHP Code:
$this->force_login(); 

If the user is already logged in, the application will simply continue with what it was doing. Otherwise, the user is routed to the login page, and after logging in, the application continues where it was.

I hope this will help you.
Reply


Messages In This Thread
RE: Load a controller into another controller - by Wouter60 - 08-13-2019, 08:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB