Codeigniter module configuration and ACL
I am developing a site in codeigniter divided into modules using HMVC. I want the modules to be enabled/disabled by an administrator, and following is how I am planning to achieve it. Since I don't have much experience in PHP/Codeigniter, the following way could be very wrong, so am looking for suggestions/feedbacks:
DB Table: Modules ID | NAME | STATE
Above table will contain all the module information, and the state field will contain 开发者_StackOverflow中文版the disabled/enabled value(0 or 1).
I am going to extend the main CI_Controller, and have a function to check the status of the module:
class MY_Controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->Model('Module_model'); //loads the module model
}
function check_module_state($module_name = '')
{
return $this->Module_model->getState($module_name); //the model returns TRUE or FALSE
}
Now, in the constructor of every controller, I will extend the MY_Controller class, and call the check_module_state
and if it returns FALSE, will redirect the user to a "Section Disabled Page";
class Module1 extends MY_Controller{
public function __construct()
{
parent::__construct();
if($this->check_module_state('module1') == FALSE)
redirect('module_disabled', 'location');
}
}
Will the above work, is there a better and easier alternative? Thanks
It looks ok. How you describe the functionality sounds good. I would however say that if a module is disabled it isn't necessary to tell people that it is disabled.
How I would approach this problem is as below.
I would use the module table to construct the navigation items. If a module is enabled allow a link to be displayed to that module. If the module is disabled no link is displayed. This would not mean you can get rid of security in your controllers as people may still URL Surf. In the case of URL Surfing to a disabled module I would silently re-direct to a default module, for example, the site root (Index).
精彩评论