0

我正在使用带有 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

或者

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";

如何使 URLsitename.com/manage/properties/edit/10工作?

4

2 回答 2

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

网站名称.com/manage/edit/10

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

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

于 2015-02-21T13:27:07.900 回答
0

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

第二。您的模块和控制器的名称都相同。因此,当您调用 localhost/manage时,它​​会默认 将其重定向到manage/manage/index,但是当您调用 localhost/manage/update 时,它​​会尝试查找名为 update 的控制器。所以像这样调用 localhost/manage/manage/update

于 2015-04-18T09:42:53.190 回答