-1
我的控制器代碼不能在笨
function edtpost($id)
{
$this->load->model('post');
$data = $this->post->edt_post($id);
$this->load->model('category');
$data['catname'] = $this->category->retrivecat();
$this->load->view('dashboard/edit_post',$data);
}
我的模型代碼
模型後
public function edt_post($id)
{
$query = $this->db->get_where('post', array('id' => $id));
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
return $row;
}
}
return false;
}
分類模型
使用類型爲stdClass的對象作爲一個數組public function retrivecat()
{
$query = $this->db->get('category');
foreach ($query->result() as $row)
{
$data[] = $row->catname;
}
return $data;
}
在控制器&這個代碼$data['catname'] = $this->category->retrivecat();
我有一個錯誤:
Cannot use object of type stdClass as array
是對你有幫助? –
謝謝,它的工作 –
最受歡迎:) –