我已经检查了其他重复的标题,但这并没有给我答案我的问题。我有这个错误,我仍然无法修复:
当我点击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>;
这是我的Controller 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);
}
当我var_dump($ data)时,我可以看到数据已经传递给View,这是我的模型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();
}
最后这是我的查看代理/仪表板,我在这上面使用了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 } ?>
如何解决这个问题?
答案 0 :(得分:0)
user是一个数组,您将其视为一个对象。这就是它给出错误的原因,试图获取非对象的属性(在这种情况下,是一个数组)。 试试:
$u['user']
$u['private_identity'] ...