【问题标题】:CodeIgniter Controller displays blank page when calling parent constructorCodeIgniter 控制器调用父构造函数时显示空白页
【发布时间】:2016-03-02 10:06:07
【问题描述】:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Home extends MY_Controller {
      public function __construct(){
          parent::__construct();
      }
}

代码在调用父构造函数后停止执行,完全没有给出任何错误消息。如果我在构造函数调用之前回显某些内容,则会回显它。如果我从自动加载库中删除数据库,它将显示错误消息。我在数据库文件上配置了正确的数据库详细信息。有人请帮帮我吗?

【问题讨论】:

  • 在 codeigniter 中启用错误日志,向我们展示日志。我们可以提供帮助。 :) stackoverflow.com/questions/3209807/…
  • 嗨,我的 index.php 有 error_reporting(E_ALL);但不显示任何错误。它在本地工作正常。问题仅在服务器中。
  • 我认为错误报告已被禁用。在 eindex.php 中检查 switch(ENVIRONMENT) ,将 E_ALL 设置为生产。
  • if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'development': error_reporting(E_ALL);休息;案例“测试”:案例“生产”:error_reporting(E_ALL);休息; default: exit('应用环境设置不正确'); } }
  • 你能在 Home 控制器中添加一个 index() 方法并从中回显吗?

标签: php codeigniter


【解决方案1】:

这个问题的信息很少,无论如何我会发布这个答案,以便您可以调试您的程序。如果您可以提供更多信息,我也可以编辑答案。

听起来你在MY_Controller 中可能有问题,请确保将你的 Home Controller 替换为以下代码。

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

class Home extends CI_Controller {

      public function index(){
         echo "hey I am working";
     }
}

如果可行,我们可以得出结论,您的MY_Controller 有错误。在这种情况下,我们需要查看MY_Controller 以提供进一步帮助。

【讨论】:

  • 嗨,它不工作。$autoload['libraries'] = array('database', 'session','form_validation','pagination', 'admin_lib');如果我从中删除数据库这部分它会起作用。
  • 你可以尝试一个一个删除吗?然后我们可以找到原因的确切位置。
  • 确定了问题。我使用dbdriver作为mysql。但在我的服务器中,它是 Mysqli。当我更改 $db['default']['dbdriver'] = 'mysqli';在databse.php 中,它运行良好。非常感谢支持
  • 很高兴您自己修复了它。 :)
猜你喜欢
  • 1970-01-01
  • 2016-04-19
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 1970-01-01
  • 2021-09-09
  • 2020-05-06
  • 1970-01-01
相关资源
最近更新 更多