繁体   English   中英

CodeIgniter 3没有调用默认控制器?

[英]CodeIgniter 3 not calling default controller?

我被要求调查一个似乎未调用CodeIgniter 3项目中的default_controller的问题。 相反,我们看到404错误。

application/controllers文件夹中,有一个Welcome.php文件,其内容如下:

class Welcome extends CI_Controller {

        public function __construct()
        {
                parent::__construct();
                // Your own constructor code
        }

        public function index()
        {
                print('hello');
                $this->load->view('welcome_message');
        }
}

application/config/routes.php文件具有:

$route['default_controller'] = "welcome";

我只看到404,但没有看到预期的文字。

将一条print语句添加到routes.php表明它正在被加载。 同样,将其显式绑定到路由会调用它,但是将其设置为默认控制器时不会调用它。

$route['blah'] = "welcome"

谁能建议可能会发生什么?

顺便说一句,我们在Ubuntu 16.04机器上使用PHP7。

原来,该项目是CodeIgniter 2项目的升级,并且其中一些迁移步骤尚未完全完成。 原来,在libs文件夹中有一个MY_Router.php,这似乎很麻烦-至少将其移入应用程序/核心可以解决此问题。

给定文件名的大写形式,需要在MY_Router.php文件中进行其他修改,作为CI3迁移的一部分:

function _validate_request($segments)
{
    // Does the requested controller exist in the root folder?
    if (file_exists(APPPATH.'controllers/'.ucfirst($segments[0]).'.php'))
    {
        return $segments;
    }
    ...
}

顺便说一句,我确定这不是HTTP服务器重写问题,因为CodeIgniter 404错误页面显示了预期的调用路径。 我添加了一个print(_SERVER['REQUEST_URI'])以查看发生了什么。

编辑:我现在看到上面的ucfirst方法在其他安装中并不理想,但是鉴于该项目的controllers文件夹中没有子文件夹,因此可以快速解决该项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM