我在 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/