我无法在我的模型中访问我的功能。这是我的代码:
控制器 service_category.php
class Service_Category extends MX_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data = array();
$data['system_title'] = 'Admin- Service Category';
$data['header'] = modules::run('common/header/index', $data);
$data['sidebar_left'] = modules::run('common/sidebar_left/index', $data);
$data['sidebar_right'] = modules::run('common/sidebar_right/index', $data);
$data['footer'] = modules::run('common/footer/index', $data);
$breadcrumbs = array(
'home' => site_url('users/user'),
'service category' => site_url('reports/service_category'),
);
$data['breadcrumbs'] = gen_breadcrumbs($breadcrumbs);
$this->load->model('reports/Service_category');
$services = $this->Service_category->get_category(); //error here cant locate
fp($services);
$this->load->view('service_category', $data);
}
}
型号 Service_category.php
class Service_category extends CI_Model {
public function __construct() {
parent::__construct();
}
public function get_category() {
$services = $this->db->get('tr_project_services');
if($services) {
return $services->result();
} else {
return array();
}
}
}
这是我的错误:
Fatal error: Call to undefined method Service_Category::get_category()
A PHP Error was encountered
Severity: Error
Message: Call to undefined method Service_Category::get_category()
Filename: controllers/service_category.php
Line Number: 25
Backtrace:
我将模型放在模块中。
答案 0 :(得分:0)
好的,我找到了问题的答案。我需要替换的只是我的型号名称。我不知道这是否是一个新的命名惯例。
我所做的是将模型名称Service_category
替换为Service_model