似乎在这里经常出现此错误,查看答案我仍然无法弄清楚为什么会出现错误。
我收到错误
致命错误:在第83行调用非对象上的成员函数 result()
有问题的行与控制器中的此功能有关- 这就是造成错误的原因。
$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 查询会带来一些结果。