子文件夹codeigniter 3中的默认控制器不起作用

问题描述:

在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'] ='home/Welcome';

$route['default_controller'] = 'home/Welcome';