我剛開始在浪費時間花費大量時間從頭開始研究PHP框架。我想我會給朋友推薦給我的Codeigniter。這個Codeigniter代碼是否正確?
我通過第一個教程工作,沒有問題,但我陷入了第二個問題。
起初,我的代碼是相同的教程:
<?php
class Blog extends CI_Controller{
function Blog()
{
parent::CI_Controller();
$this->load->scaffolding('entries');
}
public function index(){
$data['title'] = "My Blog Title";
$data['heading'] = "An intresting title";
$data['todo'] = array('create media player','design site','finish project');
$this->load->view('blog_view',$data);
}
}
?>
但我得到一個內部服務器錯誤。在查看用戶指南後,它顯示了使用構造函數的不同方式。
我將代碼更改爲文檔規範。
<?php
class Blog extends CI_Controller{
public function __construct() {
parent::__construct();
$this->load->scaffolding('entries');
}
public function index(){
$data['title'] = "My Blog Title";
$data['heading'] = "An intresting title";
$data['todo'] = array('create media player','design site','finish project');
$this->load->view('blog_view',$data);
}
}
?>
但我仍然得到一個內部錯誤。我不知道我的代碼是否錯誤,或者我配置了其他的東西。有些建議很好,謝謝。
編輯: 澄清 - 當我將構造函數添加到類時,我只會得到一個內部錯誤。
當web服務器配置錯誤時,您可能會發生內部錯誤。其他應用程序是否正常工作? – 2011-06-03 10:46:48
是的,只有當我有構造函數時它不起作用 - 我將編輯這個問題。 – Sheldon 2011-06-03 10:50:24
你正在關注哪個教程?這對於其他人試圖找到同樣問題的答案很重要。 – erisco 2011-06-03 13:55:36