问题描述
在 codeigniter 3 应用程序中,我的目录结构如下:
In codeigniter 3 application i have directory structure like this:
-Myproject
-application
-controllers
-home
Welcome.php //This is my controller inside home directory
如何将欢迎控制器设置为默认控制器?我使用下面的代码
How to set Welcome controller as default controller? I use below code
$route['default_controller'] = 'home/Welcome';
此路由适用于以前版本的 codeigniter.
This routing works for previous versions of codeigniter.
推荐答案
默认情况下,您不允许这样做.为了解决这个问题,你需要破解你的系统 Router.php
:
By default, you are not allowed to do that. To get around this, you need to hack your system Router.php
:
codeigniter/system/core/Router.php
codeigniter/system/core/Router.php
编辑几行代码,使其变成这样:
Edit a few lines of code so that it becomes like this:
第 1 行.if (!sscanf($this->default_controller, '%[^/]/%[^/]/%s', $directory, $class, $method) !==2)
第 2 行.if (!file_exists(APPPATH.'controllers'.DIRECTORY_SEPARATOR.$directory.DIRECTORY_SEPARATOR.ucfirst($class).'.php'))
第 3 行.$this->set_directory($directory);
完成后,您可以调用目录下的默认控制器.
Once you've done, you can call the default controller under directory.
$route['default_controller'] = '家/欢迎';
$route['default_controller'] = 'home/Welcome';
这篇关于子文件夹 codeigniter 3 中的默认控制器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!