我已經在codeigniter 3.0上的控制器的子文件夾中創建了控制器文件。如何使用codeigniter 3.0在子文件夾內調用控制器?
我正在使用查詢字符串formate的URL不段。
我有兩種類型的後端(admin)和前端(用戶)的子文件夾。
我也在應用程序文件夾的核心文件夾中創建了MY_Router文件。
控制器的結構
Controller
--backend
---admin.php
---product.php
--frontend
---user.php
我想要的網址爲管理面板:每個後端控制器調用之前
http://localhost/DemoSite/admin_panel/admin/dashboard
admin_panel想在URL
管理是控制
儀表板是功能
對於前端:
http://localhost/DemoSite/user
我做了這樣的路線:
$route['default_controller'] = 'frontend/user';
$route['admin_panel/(:any)'] = "backend/$1";
$route['(:any)'] = "user/$1";
MY_Router文件代碼:
<?php
class MY_Router extends CI_Router {
protected function _set_default_controller() {
if (empty($this->default_controller)) {
show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
}
// Is the method being specified?
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
if (is_dir(APPPATH . 'controllers/' . $class)) {
$this->set_directory($class);
$class = $method;
if (sscanf($method, '%[^/]/%s', $class, $method) !== 2) {
$method = 'index';
}
}
if (!file_exists(APPPATH . 'controllers/' . $this->directory . ucfirst($class) . '.php')) {
return;
}
$this->set_class($class);
$this->set_method($method);
// Assign routed segments, index starting from 1
$this->uri->rsegments = array(
1 => $class,
2 => $method,
);
log_message('debug', 'No URI present. Default controller set.');
}
}
你昨天問過同樣的問題..見:http://stackoverflow.com/questions/ 35627730/how-to-routes-controller-sub-folder-using-codeigniter#comment58937353_35627730 –
這將幫助你http://stackoverflow.com/questions/6529026/codeigniter-default-controller-in-a-sub-directory-不工作 – Gopalakrishnan
檢查這個http:// stackoverflow。com/questions/12443275/how-to-call-sub-folder-controller-with-routing-codeigniter?rq = 1 –