![](/img/trans.png)
[英]CodeIgniter Controller displays blank page when calling parent constructor
[英]CodeIgniter Controller breaks when calling parent constructor
我在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中也沒有任何內容出現。 如果我在構造函數調用之前回顯一些東西,它就會被回顯。 如果我在構造函數調用之前鍵入亂碼,則會打印正確的錯誤消息。 為什么會這樣?
該站點使用Code Igniter 2.1.4在Ubuntu服務器12.04上運行。 和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/database.php
中將'dbdriver' => 'mysqli'
更改為'dbdriver' => 'mysql'
來解決。 還要確保數據庫連接參數正確。
我的猜測,我必須看到你的配置,確保你的Loader
初始化存在問題。 最常見的是這與自動加載的庫有關,有時它與錯誤的數據庫配置有關。 我的第一個建議是嘗試使用默認配置工作。 如果有效,那么你有一個很好的起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.