I’m using CodeIgniter and I want to create some sort of filter to know when a user may/may not access a current controller
If anyone has any idea how to implement this in a different manner, great, but what I was thinking (and trying to do) is the following:
CI_Controller – which is the basic CodeIgniter controller class
MY_Controller – the basic controller which I use which extends CI_Controller
[Controller] – any “physical” controller
what i’ve tried to do is:
MY_Controller.php
class MY_Controller extends CI_Controller{
private static $namespace = null;
private static $permission = array('site', 'settings');
public function __construct(){
if ((!isset($_SESSION['user'])) && (in_array(__CLASS__, $permission))){
throw new Exception('Unauthorized');
}
parent::__construct();
}
}
obviously, this doesn’t work as CLASS will always be that of MY_Controller and not that of the child object… and NAMESPACE doesn’t work aswell.
Anyone has any idea? because Id really hate to start putting this snippet of code in every other class, and I’ll prolly need the filtering later for some more elaborate things…
I solved it in the following manner… simply in the constructor, I defined the current class
when calling the physical controller, we simply write as follows