2017-02-14 99 views
0

我已經檢查了其他重複的標題,但沒有給我答案我的問題。我有這個錯誤,我仍然無法修復:消息:試圖獲取非對象的屬性

Screenshot

當我點擊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>; 

這裏是我的控制器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($數據),我可以看到數據已經傳遞給視圖,這是我的模型型號/ 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

它告訴你#28行,哪一個「好」的代碼會碰巧指出? – MonkeyZeus

+0

這是錯誤的先生,'txtDisplayName'無法獲得'<?php echo $ u-> user的數據; ?> – justAbeginner

+0

我對這個諷刺並不抱歉,所以在發佈你的問題時指出重要的廢話,以免人們浪費時間,這對你最有利。不管怎樣,錯誤告訴你'$ u'不是一個對象。在視圖中的foreach()'循環之前添加'var_dump($ user);'或'echo';'並用輸出編輯你的問題。如果有像密碼那樣敏感的東西,那麼就用密碼或其他任何東西替換它。 – MonkeyZeus

回答

0

用戶是一個數組,您將它視爲一個對象。這就是爲什麼它給出一個錯誤,試圖獲得非對象的屬性(在這種情況下,一個數組)。 嘗試:

$u['user'] 

$u['private_identity'] ... 
+0

我已經做了,但仍然得到這個'消息:試圖獲得非對象的屬性' – justAbeginner

+0

是否需要像這樣'json_encode($ u ['private_identity'])'或者只是簡單和簡單'$ u [ 'private_identity']'? – justAbeginner

+0

使用PHP函數gettype($ u)爲了找出類型 – Sidra

相關問題