0
我無法在我的模型中訪問我的功能。這裏是我的代碼:使用Codeigniter 3 w/HMVC無法找到模型內部的功能
控制器 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:
我把我的模型放入模塊中。
和你的控制器以及文件名必須是Service_category.php – user4419336
除非使用命名空間,類需要有區別地命名。您的模型和控制器被命名爲相同。 – Tpojka