Welcome Guest, Not a member yet? Register   Sign In
Login class
#1

[eluser]Unknown[/eluser]
Hello,
I want to create a global function that checks if the user is logged in and redirect to specific page without calling it in every page

any idea?

thanks

Yaron
#2

[eluser]flaky[/eluser]
something like this could be done, there are some other ways also

Code:
//put this class in the application/libraries folder
class Application extends Controller {

    public function __construct() {
        parent::__construct();
        
        if(!$this->session->userdata('user_id'))
            redirect("user/login");
    }

}

//this one is one of your controllers in the application/controllers
class Page extends Application {

    public function __construct() {
        parent::__construct();
        
        //your constructor code
    }
    
    public function index() {
        //your code
    }

}
#3

[eluser]LuckyFella73[/eluser]
Like Flaky posted extending the CI Controller is a good way
to do get the wanted result.

A more detailed post about that can be found on Phil Sturgeons block:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY




Theme © iAndrew 2016 - Forum software by © MyBB