【发布时间】:2018-03-20 23:24:03
【问题描述】:
我有一个使用 HMVC 的 codeigniter 应用程序,但对于身份验证,我有一个控制器 Auth.php,我把它放在一个基本的 Codeigniter 控制器文件夹中,而不是在 HMVC 的模块文件夹中。
我仅在模块文件夹中的控制器上使用此重映射功能。在每个模块控制器中都有此代码。
public function _remap($method) {
$segment = $this->uri->segment(4);
switch ($method) {
case 'view':
if($segment === 'create') {
$this->create_view();
} elseif($segment === 'update') {
$this->update_view();
} else {
$this->search_view();
}
break;
case 'process':
if($segment === 'create') {
$this->create_process();
} elseif($segment === 'update') {
$this->update_process();
} else {
$this->delete_process();
}
break;
default:
$this->main_view();
break;
}
}
问题是,如何在每个模块控制器中删除此代码?我正在测试使用扩展 MX_Controller 的 MY_Controller 来放置代码。正在工作,但在我的 Auth.php 中扩展 CI_Controller 是错误的。我一直在使用钩子进行测试,但没有运气。有没有办法做到这一点?
【问题讨论】:
标签: hook codeigniter-3 remap