这可能会被标记为重复项,但由于我无法获得特定的解决方案,因此最好尝试一下。
我的控制器功能似乎导致“尝试获取非对象的属性”错误。我想从数组的索引中获取特定的数据。该数组来自我在另一页中使用的Session数据。
function within my controller
public function checkPwd()
{
$oldPwd = $this->input->post('oldPass');//getting POST data from ajax
$newPwd = $this->input->post('newPass');//getting POST data from ajax
$currLogged = $this->session->all_userdata();
foreach ($currLogged as $log)
{
echo $log->pwd; //this results to Trying to get property of non-object
}
}
答案 0 :(得分:0)
您可以通过以下方式访问它
echo $currLogged['logged'][0]->pwd
在foreach中,您可以通过以下方式访问它
foreach($currLogged as $log){
echo $log[0]->pwd;
}