无法从控制器调用模型功能

时间:2016-09-13 02:08:54

标签: codeigniter undefined

我的代码有问题,如下所示 我的错误如下 (!)致命错误:在第65行的C:\ wamp \ ... controllers \ fk_controller.php中调用未定义的方法Agentie_model :: get_agentii_list()

控制器:fk_controller

public function __construct() {
    parent::__construct(); 
    $this->load->model('agentie_model');
    $this->load->model('fk_model');
}

public function add2() {
    $this->load->model('agentie_model');         

    $data['principal'] = $this->agentie_model->get_agentii_list(); //Here is the error(line 65) 
    $this->load->view('lista_agentii', $data);
}

型号:agentie_model

private $_table = "agentii";

public function get_agentii_list() {
    $query = $this->db->get($this->_table);
    return $query->result();
}

查看:lista_agentii

echo "Lista agentii:</br>";

foreach($principal as $list) {
   echo $list->nume_agentie;
}

2 个答案:

答案 0 :(得分:0)

 public function __construct()
 {
   parent::__construct(); 
   $this->db = $this->load->database('default', true); 
 }


 public function add2() 
{
$this->load->model('Agentie_model',true);         
$data['principal'] = $this->Agentie_model->get_agentii_list(); //Here     
$this->load->view('lista_agentii', $data);
}

答案 1 :(得分:0)

控制器中的

设置如下

 function fk_controller() {
         parent::__construct(); 
         $this->load->model('agentie_model');
         $this->load->model('fk_model');
    }

    public function add2() {
        $this->load->model('agentie_model');         

        $data['principal'] = $this->agentie_model->get_agentii_list(); //Here is the error(line 65) 
        $this->load->view('lista_agentii', $data);
    }
在模型视图中

  class Agentie_model extends CI_Model 
  {
      public function get_agentii_list() {
      $query = $this->db->get($this->_table);
      return $query->result();
  }
}