<span style= "Background-color:rgb (247, 252, 255); Font-family:verdana, Arial, Helvetica, Sans-serif; "></span><p><span style=" Font-family:verdana, Arial, Helvetica, Sans-serif;
font-size:14px;
Background-color:rgb (247, 252, 255);
The >ci hook function allows you to change or add core operating functions of the system without modifying the core files of the system. </span></p><p><span style= "Font-family:verdana, Arial, Helvetica, Sans-serif;
font-size:14px; Background-color:rgb (247, 252, 255); ">
For example, you can run a specific control before the controller has just loaded or just loadedScript, or at other times to trigger yourScript.
</span></p><p><span style= "Font-family:verdana, Arial, Helvetica, Sans-serif;
font-size:14px;
Background-color:rgb (247, 252, 255);
> See Code: </span></p><pre name= "code" class= "PHP" ><span style= "Background-color:rgb (247, 252, 255); Font-family:verdana, Arial, Helvetica, Sans-serif; ">
</span>
add a hook declaration in system/application/config/hooks.php:
[PHP]
$hook [' post_controller_constructor '] = Array (
' class ' = ' Acl ',
' function ' = ' filter ',
' filename ' = ' acl.php ',
' filepath ' = ' hooks ',
);
system/application/config/config.php Hook system in effect
$config [' enable_hooks '] = TRUE;
then create a new acl.php permission system profile in, and you can also put it in the database.
//Visitor permissions Mapping
$config [' ACL '] [' visitor '] = Array (
' = = Array (' index '),//home www.2cto.com
' music ' = = Array (' index ', ' list '),
' user ' = = Array (' index ', ' login ', ' register ')
);
//Administrator
$config [' ACL '] [' admin '] = Array (
);
//-------------prompt with insufficient permissions to configure and jump URL------------------//
$config [' acl_info '] [' visitor '] = Array (
' info ' = ' need to log in to continue ',
' return_url ' = ' user/login '
);
$config [' acl_info '] [' more_role '] = Array (
' info ' = ' requires higher privileges to continue ',
' return_url ' = ' user/up '
);
/ * End of File acl.php * /
/* location:./application/config/acl.php */
add acl.php logical processing file under System/application/hooks directory
class Acl
{
private $url The modules accessed by _model;//, such as: Music
private $url methods accessed by _method;//, such as: Create
private $url _param;//url with parameters that may be 1 or id=1&name=test
private $CI;
function Acl ()
{
$this->ci = & Get_instance ();
$this->ci->load->library (' Session ');
$url = $_server[' php_self ');
$arr = explode ('/', $url);
$arr = Array_slice ($arr, Array_search (' index.php ', $arr) + 1, COUNT ($arr));
$this->url_model = isset ($arr [0])? $arr [0]: ';
$this->url_method = Isset ($arr [1])? $arr [1]: ' Index ';
$this->url_param = Isset ($arr [2])? $arr [2]: ';
}
function filter ()
{
$user = $this->ci->session->userdata (' user ');
if (Emptyempty ($user)) {//Visitor visitor
$role _name = ' visitor ';
} else {
$role _name = $user->role;
}
$this->ci->load->config (' ACL ');
$acl = $this->ci->config->item (' ACL ');
$role = $acl [$role _name];
$acl _info = $this->ci->config->item (' Acl_info ');
if (array_key_exists ($this->url_model, $role) && In_array ($this->url_method, $role [$this->url _model])) {
;
} else {//no permissions, give hint, jump URL
$this->ci->session->set_flashdata (' info ', $acl _info[$role _name][' info ');
Redirect ($acl _info[$role _name][' Return_url ');
}
}
}