简体   繁体   English

消息:试图获取非对象的属性

[英]Message: Trying to get property of non-object

I already check other duplicate title but that doesn't give me the answer to my problem. 我已经检查了其他重复的标题,但这并没有为我的问题提供答案。 I'm having this error and I still can't fix: 我遇到此错误,但仍然无法修复:

截图

When I click on the agent_dashboard (on the side) I notice this error. 当我单击agent_dashboard(在侧面)时,我注意到此错误。

txtDisplayName = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: agent/dashboard.php</p>
<p>Line Number: 28</p>

</div>;
        txtPrivateIdentity = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: agent/dashboard.php</p>
<p>Line Number: 29</p>

</div>;
        txtPublicIdentity = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: agent/dashboard.php</p>
<p>Line Number: 30</p>

</div>;
        txtPassword = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: agent/dashboard.php</p>
<p>Line Number: 31</p>

</div>;
        txtRealm = <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: agent/dashboard.php</p>
<p>Line Number: 32</p>

</div>;

Here's my Controller Main_Controller/agent_dashboard 这是我的控制器Main_Controller / agent_dashboard

public function agent_dashboard() {
  $this->load->library('session');
  $user = $this - > session - > userdata('user');
  $data['user'] = $this - > Model - > each_user_data($user);
  //var_dump($data);
  $this - > load - > view('agent/dashboard', $data);
}

when I var_dump($data) I can see that the data already pass to the View and this is my model Model/each_user_data 当我var_dump($ data)时,我可以看到数据已经传递到视图,这是我的模型Model / each_user_data

public function each_user_data($user){
        $this->db->select('user');
        // $this->db->select('user_level');
        $this->db->select('full_name');
        $this->db->select('pass');
        $this->db->select('private_identity');
        $this->db->select('public_identity');
        $this->db->select('realm');
        $this->db->where('user', $user);
        $query = $this->db->get('t_users');
        return $query->row();
    }

Lastly this is my view agent/dashboard, I use jquery on this. 最后,这是我的视图代理/仪表板,对此我使用了jQuery。

<?php foreach($user as $u) {?>
            var txtDisplayName;
            var txtPrivateIdentity;
            var txtPublicIdentity;
            var txtPassword;
            var txtRealm;


        txtDisplayName = <?php echo $u->user; ?>;
        txtPrivateIdentity = <?php echo $u->private_identity; ?>;
        txtPublicIdentity = <?php echo $u->public_identity; ?>;
        txtPassword = <?php echo $u->pass; ?>;
        txtRealm = <?php echo $u->realm; ?>;

        <?php } ?>

How to solve this? 如何解决呢?

user is an array and you are treating it as an object. 用户是一个数组,您将其视为对象。 This is why it's giving an error, trying to get property of non-object (in this case, an array). 这就是为什么它给出错误,试图获取非对象(在本例中为数组)的属性的原因。 try : 尝试:

 $u['user'] 

 $u['private_identity'] ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM