3

我正在使用 HMVC 并创建了一个名为 user 的模块。在 modules/user/config 目录中,我有 routes.php,使用与 application/config/routes.php 相同的格式。

在 application/config/routes.php 我有以下路线:

$route['login'] = 'user/login';

这很好用,但是当我将它移到 application/modules/user/config/routes.php 时,它不起作用。我收到 404 错误。

根据 HMVC 文档 ( https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc),您必须按如下方式创建路由:

$route['module_name'] = 'controller_name';

这意味着我将不得不这样做:

$route['user'] = 'user';

这会导致 404,但是,即使我没有得到 404,这也不是我的想法。当/login 转到用户/登录时,我仍然希望保持我的路由正常工作。

任何想法将不胜感激!

谢谢!

4

1 回答 1

3

I had the same exact problem as you, unfortunately the way Wiredesignz created the extension it requires that the path start with the module name itself if you put the routes file inside the module itself. That is the only way it will look at the routes file if it is placed inside a module. With that said it already knows the module name at that point, so you need to simply specify the controller and method that you want it to route to. So in your routes.php file inside of your module config directory, if you put this:

$route['yourmodule/some-route'] = "yourcontroller/yourmethod";

or in other words:

$route['user'] = 'user/login';

That would work I believe. However I still wanted more than this. I wanted to be able to use routes that may or may not have the module name. Due to this I had to extend the module to make this happen, and you can find the work I did here if this helps:

https://github.com/brianwozeniak/codeigniter-modular-extensions-hmvc

This would then allow you to use the route you wanted such as:

$route['login'] = 'user/login';

Even with that routes.php placed inside the module's config directory.

于 2013-04-08T22:02:24.377 回答