在codeigniter中使用子文件夹会导致问题

时间:2014-07-23 10:10:42

标签: php codeigniter controllers subdirectory

我在CI网络应用中遇到了找不到网页的错误 我有3个单独的子文件夹,里面有控制器,管理员,站点,成员。结构看起来像这样。

- Controllers
--- Site
----- site.php <-- handles all general site pages
--- Members
----- dashboard.php <-- default controller to be called when no parameter is passed
----- products.php <-- handles all products request
--- Admin
---- dashboard.php <-- default controller to be called when no parameter is passed
---- members.php <-- handles all members request

我尝试在routes.php文件中路由它,就像这样

// Admin - folder/controler/Method

$route['admin/(:any)'] = 'admin/admin/$1';
$route['admin'] = 'admin/dashboard/index'; 

$route['clients/(:any)'] = 'clients/$1';
$route['clients'] = 'clients/dashboard/index';

$route['(:any)'] = 'site/$1';
$route['default_controller'] = 'site/index';

$route['404_override'] = '';

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

请尝试

// Admin - folder/controler/Method

$route['default_controller'] = 'site';
$route['404_override'] = '';

$route['admin/(:any)'] = 'admin/admin/$1';
$route['admin'] = 'admin/dashboard'; 


$route['clients/(:any)'] = 'clients/$1';
$route['clients'] = 'clients/dashboard';



$route['(:any)'] = 'site/$1';
  • 摆脱方法(index
  • 不同的顺序
  • 让保留路线在顶部

路由顺序很重要,当CI找到第一个有效路线时,它不会在列表中执行其他路线。