【问题标题】:using subfolders in codeigniter causes problems在 codeigniter 中使用子文件夹会导致问题
【发布时间】:2014-09-14 11:16:58
【问题描述】:

我的 CI Web 应用程序中出现 page not found 错误 我有 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'] = '';

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

【问题讨论】:

    标签: php codeigniter controllers subdirectory


    【解决方案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 找到第一个有效路由时,它不会执行列表中的其他路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 2014-11-16
      • 1970-01-01
      • 2020-08-25
      • 2013-05-22
      相关资源
      最近更新 更多