我有以下的情況發生在我的模型:訪問結果數組中的笨
public function load_user_menu($username)
{
$this->db->select('*');
$this->db->from('menu');
$this->db->where('username', $username);
$query = $this->db->get();
return $query->result();
}
,並在我的控制器如下:
public function index()
{
/*If user previously logged in and not logged out, username remains in session.
load username and load profile data.
*/
//check if user logged in or not
if(($this->session->userdata('username')!=""))
{
//load data from model
$profile = array();
$username = $this->session->userdata('username');
$result = $this->profileModel->user_profile($username);
foreach($result as &$value)
{
$profile['userdetails'] = $value;
}
$this->load->view('profile', $profile);
}else{
//redirect to login function
$this->login();
}
}
,但我得到的曲線圖的錯誤。我相信我訪問他們錯了,因爲我做這個的觀點:
<? echo $userdetails['profilepic']; ?>
,並沒有什麼出,但這個錯誤:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/profile.php
Line Number: 60
這是因爲錯誤的接入的肯定。我如何根據上述內容訪問細節?
哪裏是'$的UserDetails [ 'profilepic'];'在你的代碼?該錯誤表示沒有任何東西可以從該變量中獲得,並且沒有任何東西進入'$ userdetails ['profilepic'];'中。 – MahanGM
那麼錯誤中提到的代碼是什麼? –