为什么$ this->数据未发送到视图,但是$ data在CodeIgniter中? [英] Why is $this->data not sending to view, but $data is in CodeIgniter?

查看:45
本文介绍了为什么$ this->数据未发送到视图,但是$ data在CodeIgniter中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这正在发送数据以在CodeIgniter中查看:

This is sending data to view in CodeIgniter:

    public function index()
    {           
        $data['header'] = "Home";
        $this->load->view('admin_frontpage', $data);
    }

这不是:

    public function index()
    {
        $this->data['header'] = "Home";
        $this->load->view('admin_frontpage', $this->data);
    }

为什么?

在我的查看文件中,我尝试回显:

In my view file I try to echo:

    <?php echo $header; ?>

但仅在使用$ data时才回显。在控制器中使用$ this-> data时,没有任何回显。

But only when using $data it is echoed. When using $this->data in controller, nothing is echoed out.

我在做什么错了?

推荐答案

最有可能是未定义 $ this->数据

您需要在您的课程中定义一个数据成员

You need to define a data member in your class

private $data;

并使用

$this->data = array();

或一次全部

private $data = array();

请参见类和对象属性以获取详细信息。

See Classes and Objects and Properties for details.

这篇关于为什么$ this-&gt;数据未发送到视图,但是$ data在CodeIgniter中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆