【发布时间】:2014-05-16 03:41:29
【问题描述】:
我使用代码codeigniter 制作简单的模板。 我的代码是这样的......
这是 template.php 类
class Template {
protected $_ci;
function _construct() {
$this->_ci=&get_instance();
}
function display($template, $data = null) {
$data['_content'] = $this->_ci->load->view($template, $data, TRUE);
$data['_header'] = $this->_ci->load->view('template/header', $data, TRUE);
$data['_top_menu'] = $this->_ci->load->view('template/menu', $data, TRUE);
$data['_right_menu'] = $this->_ci->load->view('template/sidebar', $data, TRUE);
$this->_ci->load->view('/template.php', $data);
}
}
这是我的控制器welcome.php类
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct(); //you always have to call parent's constructor before ANYTHING
$this->load->library('template');
$this->load->helper('url');
}
public function index() {
$this->template->display('welcome_message');
}
function contoh_parameter() {
$this->template->display('view_parameter', array('judul' => 'Judul View'));
}
}
这是我的视图类,welcome_message.php类
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
但我得到这样的错误:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/template.php
Line Number: 25
对不起,我还是 codeigniter 和 php 的新手。请帮帮我。
【问题讨论】:
-
我认为你的构造函数只有一个
_。应该是两个下划线:__constructor()
标签: php codeigniter