子目录中的 CodeIgniter 默认控制器不起作用 [英] CodeIgniter default controller in a sub directory not working

查看:28
本文介绍了子目录中的 CodeIgniter 默认控制器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在路由配置中的 default_controller 设置为home.php".

My default_controller in the routes configuration is set as "home.php".

我的控制器有一个子目录,我们称之为文件夹".因此,如果我访问 http://mysite.com/folder/,默认控制器folder/home.php"应该叫对吧?

I have a sub directory for my controllers, lets call it "folder". So if I visit http://mysite.com/folder/, the default controller "folder/home.php" should be called right?

但是由于某种原因这不起作用,我收到了 404.访问 http://mysite.com/文件夹/主页http://mysite.com/folder/home/index按预期工作.除此之外,默认控制器在根目录中工作(http://mysite.com 加载 home.php).

However for some reason this doesn't work, I get a 404. Visiting http://mysite.com/folder/home or http://mysite.com/folder/home/index works as expected. In addition to this, the default controller works in the root directory (http://mysite.com loads home.php).

任何想法,有没有其他人经历过这个?我无法理解它 - 这似乎是一个 CI 问题,但我找不到其他人有同样的问题.

Any ideas, has anyone else experienced this? I can't get my head around it - it would appear to be a CI issue but I can't find anybody else having the same problem.

至少从我理解的方式来看,文档表明这应该可以正常工作:http://codeigniter.com/user_guide/general/controllers.html#subfolders

The documentation, from the way I understand it at least, suggests that this should work fine: http://codeigniter.com/user_guide/general/controllers.html#subfolders

将默认控制器设置为folder/home.php"意味着http://mysite.com/folder/ 按预期工作正常.除了我希望默认控制器只是home.php" - 无论是在根目录中还是在子目录中,都应该加载该目录中的 home.php,如文档所建议的那样.

Setting the default controller to "folder/home.php" means that http://mysite.com/folder/ works fine as expected. Except for I want the default controller to just be "home.php" - whether in the root or in a sub directory, home.php within that directory should be loaded, as the documentation suggests.

干杯

推荐答案

对于控制器文件夹中的每个子文件夹,您必须在 routes.php 中指定一个默认控制器.内置的 $route['default_controller'] 不适用于子文件夹.

For each sub-folder in your controllers folder you must specify a default controller in routes.php. The built in $route['default_controller'] will not work for sub-folders.

例如:要为您设置默认控制器 folder 子文件夹到 home 将以下内容添加到您的 /application/config/routes.php文件:

e.g: For setting the default controller for you folder sub-folder to home add the following to your /application/config/routes.php file:

$route['folder'] = "folder/home";

这意味着 http://mysite.com/folder/http://mysite.com/folder/home 作为 URL 相同.

which means http://mysite.com/folder/ is the same as http://mysite.com/folder/home as URL.

这篇关于子目录中的 CodeIgniter 默认控制器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆