0
偏移 '姓名' 我有此錯誤:llegal字符串中笨
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'name'
Filename: user/account.php
Line Number: 72
在控制器 「account.php」 我有這樣的:
[...]
$account['account'] = $this->user_model->account($id);
$this->template->write_view('top_menu', 'top_menu');
$this->template->write_view('user', 'template/user/panel', $data, TRUE);
$this->template->write_view('left', 'template/public/menu');
$this->template->write_view('right', 'template/user/account',$account, TRUE);
$this->template->render();
在 「user_model.php」 我有這樣的:
public function account($id)
{
$query = $this->db->get_where('users', array('id' => $id));
if ($query->num_rows() == 1)
{
return $query->row();
}
else
{
return FALSE;
}
}
並在視圖我有此:
<?php foreach ($account as $row)
{
(this is the line 72) echo $row['name'];
}
?>
什麼是錯誤?謝謝你的幫助!!!
嗨kefy,這是我嚐到的第一件事,但我得到這個錯誤「嘗試獲取非對象的屬性」。感謝您的回覆如此之快。 – OsquiB 2014-09-02 18:49:45
對不起,我修好了。我忘記了刪除「foreach」。 – OsquiB 2014-09-02 18:52:18
Yups祝賀,但我的建議更新你的模型像我previouslly upadte我的答案 – kefy 2014-09-02 18:56:11