【问题标题】:CodeIgniter HMVC routesCodeIgniter HMVC 路由
【发布时间】:2014-07-18 09:40:14
【问题描述】:

目前正在使用 HMVC 开发 CodeIgniter 应用程序

HMVC 应用程序有自己的 routing.php 包含

$route['finance/bill/add'] = 'finance/show_addBill';

$route['finance/transaction/add'] = 'finance/show_addTransaction';

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

$route['finance'] = 'finance';

应用程序有一个财务控制器。 去的时候

http://localhost/finance** it goes to **public function index(){}

http://localhost/finance/transaction/add DOES NOT go to **public function show_addTransaction() {}

http://localhost/finance/addTransaction DOES goes to **public function show_addTransaction() {}

我无法弄清楚为什么上述路线不起作用:S

【问题讨论】:

    标签: codeigniter routing hmvc


    【解决方案1】:

    您不应该在 HMVC 应用程序中定义路由(作为一个非常强大的经验法则 - 有例外,但很少见)。

    你应该有一个这样的文件夹结构:

    Modules
    - Finance
    - - Controllers
    - - - finance //should have index, add and an other generic functions.
    - - - transaction // transactions specific functions
    - - - bill // bill specific functions.
    

    路由是自动的 - 按照这些思路:

    url/finance -> 寻找Modules/Finance/Controllers/Finance/Index()

    url/finance/bill -> 它将首先查找Modules/Finance/Controllers/Finance(.php)/Bill() 然后Modules/Finance/Controllers/Bill(.php)/index()

    所以对于你的场景,你应该有:

    $route['finance/bill/add']
    

    bill.php 控制器 - 带有 class bill - 带有方法 add

    $route['finance/transaction/add']
    

    transaction.php 控制器 - 带有 class transaction - 带有方法 add

    $route['finance/(:any)']
    

    不存在 - 正如我所说的那样,URL 路由是自动的,所以只要你有相关的控制器和方法,就会找到东西

    $route['finance']
    

    带有index 方法的简单finance.php 控制器。

    【讨论】:

      猜你喜欢
      • 2014-12-06
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      相关资源
      最近更新 更多