CodeIgniter默认控制器在一个子目录下不工作 [英] CodeIgniter default controller in a sub directory not working

查看:499
本文介绍了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/folder/home 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.

Cheers

推荐答案

对于控制器文件夹中的每个子文件夹,您必须在 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.

例如:将文件夹子文件夹的默认控制器 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 一样作为网址。

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

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

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