我有以下的情况发生在我的模型:访问结果数组中的笨
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
那么错误中提到的代码是什么? –