Authentication |
[eluser]elmne[/eluser]
I have the following code which requires the placing of $this->load->library('auth'); - in the constructor of a class so as to call the script in the library $this->auth->restrict(); - in the method that i wish to restrict However, this is not so convenient with many controllers and methods. How can i customise this so that i can have an additional function within "auth" that can restrict access to the entire class so that $this->auth->restrict(); - is only used to restrict a method $this->auth->restrict_class(); - a possible new function which can restrict access to an entire class or even possibly a third function restricting access to an entire folder like "admin" so that all controllers within it are innacessible without logging in? The code is shown below auth.php - which is in libraries Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); the admin controller Code: <?php
[eluser]Buso[/eluser]
the constructor Admin() is a method too, and if you restrict it, you restrict the whole class
[eluser]elmne[/eluser]
Thanks for that. Is there a way i can also restrict access to an entire folder? For instance, having something that prevents "admin" from being added to the path or checks it to see if user is logged in? I put the restrict in the admin controller but the path for subfolders and other controllers doesn't go through the admin controller, therefore i can now restrict each controller one at a time, but not all of them. If there was a way i could make it work for folders beside extending the controller class, as it creates another task of having to remember to differentiate controller class for admin from that of non-admin areas.
[eluser]Buso[/eluser]
For this I use different base controllers, eg: Frontend_Controller, Backend_Controller, Main_Controller, etc. All the backend (or admin) controllers extend Backend_Controller, that way I only have to do the check inside Backend_Controller::__construct() You will have to reaserch further on this subject, there are many approaches. I recommend you this article http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
|
Welcome Guest, Not a member yet? Register Sign In |