![](/img/trans.png)
[英]how to write routes.php file in controllar using codeigniter?
[英]routes.php file not loading when using hmvc in codeigniter?
我有hmvc设置和工作正常,
我有一个画廊模块。
gallery模块分为三个控制器,其结构如下:
/modules/gallery/
/modules/gallery/config/
/modules/gallery/helpers/
/modules/gallery/controllers/
/modules/gallery/controllers/gallery.php
/modules/gallery/controllers/galleries.php
/modules/gallery/controllers/images.php
/modules/gallery/models/
/modules/gallery/models/galleriesmodel.php
/modules/gallery/models/imagesmodel.php
/modules/gallery/views/dashboard.tpl
/modules/gallery/views/galleries/dashboard.tpl
/modules/gallery/views/images/dashboard.tpl
无论如何,我在images.php
控制器里面有一个名为list_items
的函数
所以我想映射网址
http://example.com/gallery/images/list to
http://example.com/gallery/images/list_items
所以我想,很好,我只会在其中添加一个/modules/gallery/config/routes.php
。
但似乎没有包括路线。
包含来自/application/config/routes.php
的路由,如果我在模块routes.php
放置一个die('loaded')
,它会杀死脚本,
但跑步
来自其中一个控制器的print_r($this->router)
没有显示来自routes.php
模块的任何路由。
这里发生了什么?
我所知道的,
HMVC仅在每个模块中查找所请求的控制器,具有不同的层次结构模型,但使用routes.php的路由覆盖永远不会被读取。
考虑MX_Router::locate
它从不寻找routes.php
的任何模块内。
此外,它不会覆盖CI_Router::_set_routing
看起来对routes.php
中的config文件夹。
您必须覆盖CI_Router::_set_routing
并在每个可用模块中读取config/router.php
,以使模块路由覆盖工作。
Broncha显示方式,我告诉你代码。 我用这个解决方案:
您必须在system/core/Router.php
编辑_set_routing()
或在MY_Router类( third_party/Router.php
)中扩展此方法(更好)。
现在它应该总是加载module/config/routes.php
... (它在140行左右)
// Load the routes.php file.
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
elseif (is_file(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
// Include routes every modules
$modules_locations = config_item('modules_locations') ? config_item('modules_locations') : FALSE;
if(!$modules_locations)
{
$modules_locations = APPPATH . 'modules/';
if(is_dir($modules_locations))
{
$modules_locations = array($modules_locations => '../modules/');
}
else
{
show_error('Modules directory not found');
}
}
foreach ($modules_locations as $key => $value)
{
if ($handle = opendir($key))
{
while (false !== ($entry = readdir($handle)))
{
if ($entry != "." && $entry != "..")
{
if(is_dir($key.$entry))
{
$rfile = Modules::find('routes'.EXT, $entry, 'config/');
if($rfile[0])
{
include($rfile[0].$rfile[1]);
}
}
}
}
closedir($handle);
}
}
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);
我希望它会有所帮助......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.