与HMVC无关的Codeigniter路由

时间:2015-02-21 08:00:35

标签: codeigniter routing hmvc codeigniter-hmvc

我正在使用带有HMVC的Codeigniter,我有一个名称与模块名称不同的子控制器


- modules
      - manage
        - controllers
          - manage.php
        - views
          - dashboard.php

      - properties
         - controllers
            - properties.php
            - manage.php
         - views
            - properties.php
            - manage.php
      - projects 
        - controllers
          - projects.php
          - manage.php
        - views
          - projects.php
          - manage.php

如果网址像这样(索引只能工作)

sitename.com/manage/proprties

这个工作正常,但如果我传递了一些参数,(错误404) sitename.com/manage/properties/add

OR

sitename.com/manage/properties/edit/10

我的路线像这样

$route['manage/(:any)']                     ="$1/manage";
$route['manage/(:any)/(:any)']              ="$1/manage/$2";
$route['manage/(:any)/(:any)/(:num)']       ="$1/manage/$2/$3";

如何让网址sitename.com/manage/properties/edit/10正常工作?

2 个答案:

答案 0 :(得分:0)

在路线上你错了。取决于您的codeigniter版本。

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

<强>示例:

$route['default_controller'] =" folder/controller/index"; // Only works codeigniter 2 so far codeigniter 3 will not allow is bug in codeigniter 3

$route['name'] =" folder/controller/index"; // Example

$route['manage'] =" manage/manage/index";

$route['manage/add'] =" manage/manage/add"; 

$route['manage/update/(:any)'] =" manage/manage/update/$1"; // (:any) sbsu2783
$route['manage/update/(:num)'] =" manage/manage/update/$1"; // (:num) 2783
$route['manage/update/(:any)/(:any)'] =" manage/manage/update/$1/$2"; // Just example

$route['manage/delete'] =" manage/manage/delete";

$route['manage/(:any)'] =" manage/manage/index/$1/$2"; // Not need most of the time

sitename.com/manage/edit/10

您可能需要包含index.php,或者可能不确定您是否配置了htaccess。

例如在控制器site_url('manage/update') .'/'. $this->uri->segment(4);

答案 1 :(得分:0)

如果您正在使用HMVC,那么呼叫内部控制器的功能不需要任何路由。只需正确配置即可。

二。模块和控制器的名称都相同。所以什么时候 你打电话 localhost / manage 默认情况下会将其重定向到 manage / manage / index 但是当您致电时 localhost / manage / update 它尝试查找名为update的控制器。所以这样打电话 的本地主机/管理/管理/更新