2017-02-19 128 views
0

我被要求研究CodeIgniter 3项目中的default_controller似乎没有被调用的问题。相反,我们看到一个404错误。CodeIgniter 3不调用默认控制器?

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。

+0

你的.htaccess文件怎么样? –

+0

这是怎么回事?我应该检查什么? –

+0

使用'localhost/project_name/welcome'.Any错误? –

回答

0

原来这个项目是CodeIgniter 2项目的升级版本,并且有一些迁移步骤尚未完成。事实证明,在库文件夹中有一个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方法在其他安装中并不理想,但考虑到该项目的控制器文件夹中没有子文件夹,这是该项目的快速修复。