2016-02-29 60 views
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: 

我把我的模型放入模块中。

回答

0

好的,我找到了我的问题的答案。我需要替换的是我的型号名称。我不知道这是否是一个新的命名约定。

我做什么是我代替我的型号名称Service_categoryService_model

+1

和你的控制器以及文件名必须是Service_category.php – user4419336

+0

除非使用命名空间,类需要有区别地命名。您的模型和控制器被命名为相同。 – Tpojka