Codeigniter Filters
I am working on the admin side of a site that I am building and wanted to lock it down. I already figured out how to do my authentication, but I am looking for a way to call this authentication function on every request being made in this controller without having to call i开发者_开发问答t at the beginning of each controller method. Is there a way to pass request through a filter, or something of the sort, in the constructor?
Ex.
public function __construct()
{
filter(authenticate(), 'login,signin');
}
Where the first parameter is the method being called, and the second parameter is the methods to exclude from the filter. Because you wouldn’t want to check for a logged in user if they are on the login page or if the signin method is being used since it is the one logging them in. Does anyone know if there is a way to do this? I think it would cut back on me repeating the call to authenticate before each locked down method.
Thanks!
Figured it out
Remapping looks to have done what I was looking for. Be sure to look into it! Great function :)
Have you considered using a MY_Controller?
In MY_Controller.php, create an Auth_Controller class (name it what you like) which will check if the user is logged in in the __construct() method. Then, ave all your "locked down" controllers extend Auth_Controller.
精彩评论