php - CodeIgniter Controller 在调用父构造函数时中断

标签 php codeigniter

我在 helloworld.php 中有以下代码:

<?php

class Helloworld extends CI_Controller {

public function __construct()
{
    parent::__construct();
}

public function index()
{
    $this->load->model("helloworld_model");
    $data["result"] = $this->Helloworld_model->getData();
    $data["page_title"] = "CI Helloworld appis";
    $this->load->view("helloworld_view", $data);
}

}

?>

代码在调用父构造函数后停止执行,绝对不会给出任何错误消息。/var/log/apache2/error.log 中也没有任何内容。如果我在构造函数调用之前回显某些内容,它就会被回显。如果我在构造函数调用之前键入乱码,则会打印一条正确的错误消息。为什么会这样?

该站点在 Ubuntu 服务器 12.04 上运行,带有 Code Igniter 2.1.4。和 PHP 5.3。

其他文件为helloworld_model.php:

<?php

class Helloworld_model extends CI_Model {

public function __construct()
{
    parent::__construct();
    $this->load->database();
}

public function getData()
{
    $query = $this->db->get("data");

    if ($query->num_rows() > 0)
    {
        return $query->row_array();
    }
    else
    {
        show_error("Database is empty");
    }
}

}

?>

还有 helloworld_view.php:

<html>
<head>
    <title><?php echo $page_title ?></title>
</head>

<body>
    <?php foreach($result as $row): ?>
        <h3><?php echo $row["title"]?></h3>
        <p><?php echo $row["text"]?></p>
        <br />
    <?php endforeach ?>

</body>
</html>

据我所知,Controller 构造函数绝对首先被调用,所以我认为其余文件在这个阶段并不重要(?)。

最佳答案

我遇到了同样的问题,通过在 config/中将 'dbdriver' => 'mysqli' 更改为 'dbdriver' => 'mysql' 解决了这个问题数据库.php。还要确保您的数据库连接参数正确。

关于php - CodeIgniter Controller 在调用父构造函数时中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18708302/

相关文章:

css - 我使用什么路径在 codeigniter 中调用背景图像

PHP - 保存 Tumblr API 的访问 token

php - 重定向后 Codeigniter session 数据丢失

php - codeigniter 显示 (my)sql 插入警告

php - 在 codeigniter 中一起更新和加入查询?

php - 将用户密码从加盐 SHA1 升级到 bcrypt

php - Swift (iOS) 和 PHP 中 AES256 加密的不同结果

php - 我已经编码的网站的内容管理

php - 限制不适用于 ActiveRecord

php - CodeIgniter:在 View 之间传递变量