Php 尝试获取Codeigniter模板中非对象的属性

Php 尝试获取Codeigniter模板中非对象的属性,php,codeigniter,Php,Codeigniter,我使用codeigniter制作简单的模板。 我的代码是这样的 这是template.php类 这是我的controller welcome.php类 这是我的视图类,welcome_message.php类 但我得到的错误如下: A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: libraries/template.php Line

我使用codeigniter制作简单的模板。 我的代码是这样的

这是template.php类

这是我的controller welcome.php类

这是我的视图类,welcome_message.php类

但我得到的错误如下:

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: libraries/template.php

Line Number: 25

对不起,我还是codeigniter和php的新手。请帮帮我。

首先,你的构造方法不对,它应该是
\uu-construct
而不是
\u-construct


其次,使用
$this->\u ci->load->view('/template.php',$data)加载视图时,不应在开始路径上使用任何斜杠,直到CI可以使用视图目录。因此,如果您的视图文件是CI视图文件夹中的
template.php
,则以这种方式使用它
$this->\u CI->load->view('template',$data)。您还可以使用
.php
扩展CI self添加该扩展。

我认为您的构造函数只有一个
。它应该是两个下划线:
\u构造函数()
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'));
}

}
   <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