看起來像這裏常見的這個錯誤發生,看着答案我仍然無法弄清楚爲什麼我得到一個錯誤。致命錯誤調用成員函數result() - 代碼點火器
我收到錯誤
Fatal error: Call to a member function result() on a non-object on line 83
線問題涉及的控制器這個功能 - 這是什麼產生錯誤。
$this->view_data['categories'] = $my_categories->result();
功能如下..
function _load_search_options()
{
// Get all the categories for the advanced search page
$my_categories = $this->Categories_model->get_all();
$this->view_data['categories'] = $my_categories->result();
// Get all the PRIMARY colours from teh tbl_colour_options
$my_colour_options = $this->Colours_model->get_all_primary();
$this->view_data['colour_options'] = $my_colour_options->result();
// Get all the colours from teh tbl_colour_options
$my_colour_options_all = $this->Colours_model->get_all();
$this->view_data['colour_options_all'] = $my_colour_options_all->result();
}
我的模型如下...
function get_all()
{
$query_str = "
SELECT *
FROM categories
WHERE CATEGORIES_parent_id = 0
";
$results = $this->db->query($query_str);
$parents = $results->result();
foreach ($parents as $parent)
{
$children = array();
$query_str = "
SELECT *
FROM categories
WHERE CATEGORIES_parent_id = '$parent->CATEGORIES_id'
";
$children_results = $this->db->query($query_str);
$children_results = $children_results->result();
foreach($children_results as $children_result)
{
$children[$children_result->CATEGORIES_id] = $children_result->CATEGORIES_title;
}
$categories[$parent->CATEGORIES_title] = $children;
}
return $categories;
}
值得一提的是運行在MySQL自身的SELECT查詢就會通過一些結果。
去線83和鍵入'回聲將gettype($ my_categories)'這應該回答你的問題 – Teneff
做的var_dump($ my_categories),以驗證是否爲空 –
@khaled_webdev它與大數據陣列回來.. – StuBlackett