CodeIgniter无法实例化控制器类 [英] CodeIgniter not able to instantiate controller class

查看:78
本文介绍了CodeIgniter无法实例化控制器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试解决CodeIgniter为什么不显示任何输出(404之类的除外)的原因。我已经检查了所有内容,从php和apache和codeigniter中的错误记录到模块重写。

So I'm trying to troubleshoot why CodeIgniter won't display any output (except for 404's and such). I've checked everything from error logging in php and apache and codeigniter, to the module rewriting. Everything seems to be configured just fine.

我开始深入研究CodeIgniter核心文件,并注意到它在尝试实例化所请求的控制器类的下面的行中崩溃了。 :

I started to dive into the CodeIgniter core files and noticed that it was crashing on the line below that tries to instantiate the requested controller class:

        $class  = $RTR->fetch_class();
        $method = $RTR->fetch_method();

echo 'looking for class: ' . $class . '<br/>';
if(class_exists($class) == false) {

                )
        {
                echo 'class does not exist: ' . $class;
                show_404("{$class}/{$method}");
        }
}

/*
 * ------------------------------------------------------
 *  Is there a "pre_controller" hook?
 * ------------------------------------------------------
 */
        $EXT->_call_hook('pre_controller');
echo '<br/>after precontroller';
/*
 * ------------------------------------------------------
 *  Instantiate the requested controller
 * ------------------------------------------------------
 */
        // Mark a start point so we can benchmark the controller
        $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');

echo '<br/>before class init: ' . $class;
        $CI = new $class();
echo '<br/>after class init';

这位于/core/CodeIgniter.php文件中。输出为:

This is within the /core/CodeIgniter.php file. Here is the output:

CodeIgniter.php
looking for class: servicecontroller

after precontroller
before class init: servicecontroller

基本上是告诉我可以找到servicecontroller类,但是当它尝试实例化它时,它崩溃了。启用php错误日志记录,并打开display_errors。如果我在此处附近的任何地方强加了一个php错误,我会在页面上看到它,但不是这个。没有人知道为什么它不能通过这条线吗?

Basically it's telling me that it can find the servicecontroller class, but when it tries to instantiate it, it crashes. php error logging is enabled, and display_errors is on. If I force a php error anywhere near here, I see it on the page, but not this one. Does anyone have any idea why it can't get past this line?

servicecontroller.php的排列方式如下:

servicecontroller.php is arranged like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class servicecontroller extends CI_Controller {
}


推荐答案

好的,这个问题的根源是使用mysql_connect连接到数据库时出错。由于某种原因,它不会产生任何错误,也不会产生 or die( error ...);的任何错误;这是因为我们在服务器上使用的是php 5.4,并且似乎不再支持mysql_connect ,除非您已安装mysqlnd,解决方案是将数据库驱动程序切换为CodeIgniter幸运地具有该驱动程序的'mysqli',然后使用以下命令安装php5-mysql:apt-get install php5-mysql
希望这会有所帮助其他人。

Okay, the root of this problem was an error connecting to the database using mysql_connect. For some reason, it would not produce any error whatsoever, nor would "or die("error..."); do anything. This was because we were using php 5.4 on the server, and mysql_connect does not seem to be supported anymore, unless you have mysqlnd installed. The solution was to switch our database driver to 'mysqli', which CodeIgniter luckily has a driver for, and then install php5-mysql with: apt-get install php5-mysql Hope this helps anyone else.

这篇关于CodeIgniter无法实例化控制器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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