class Admin extends MY_Controller{
function __construct(){
parent::__construct();
$this->check_permit();
$this->load->helper('url');
...
}
...
}
//MY_Controller.php下的:
protected function check_permit($action = '', $folder = '')
{
if ( ! $this->permit($action, $folder))
{
echo "<script language='javascript'>alert('您没有访问该目录的权限!');self.location.href='".base_url()."index.php/admin/right';</script>";
return FALSE;
}
}
private function permit($act = '', $folder = ''){
//.........验证权限的代码.........(用in_array()匹配的方式)
}
//就这样,每次都是先执行操作,操作完成后才执行验证,快崩溃了 !