缺少search_model :: autocomplete()的参数1,

时间:2015-07-23 08:08:06

标签: php ajax codeigniter

这是控制器search.php

public function login()
{
    $email=$this->input->post('email');
    $password=md5($this->input->post('password'));
    $result=$this->search_model->login($email,$password);   
    if(!$result) {
        $this->index();

    }

    else        {
        $this->session->set_userdata('user_id',$email);
        $seid=$this->session->userdata('user_id');
        $data['result'] =$this->search_model->autocomplete();              
        $this->load->view('pagination_view',array('result' => $result));    
    }

} 

===========================模型=================== ======================

public function autocomplete($like) {

    $this->db->select('name');
    $this->db->from('tbl_reg');
    $this->db->like('name', $like);
   // $this->db->where('status', ACTIVE);
    $q = $this->db->get();
    if ($q->num_rows() > 0) {
        return $q->result();
    }
}
在控制器search.php中

将哪个参数添加到autocomplete()。代码是

$data['result'] = $this->search_model->autocomplete();

我收到了严重错误:警告

  

消息:缺少search_model :: autocomplete()的参数1,

     

和另一条错误消息,如

Undefined variable: like

这个问题的解决方案是什么?

3 个答案:

答案 0 :(得分:3)

您需要在模型函数中传递参数

$this->search_model->autocomplete($YOUR_LIKE_VARIABLE);// pass your like variable here

因为在模型文件中使用

public function autocomplete($like) {

答案 1 :(得分:0)

你应该将like变量作为参数传递给模型函数

在您的控制器中

$like = "matching word"; // replace this with your value;
$data['result'] =$this->search_model->autocomplete($like); 

答案 2 :(得分:0)

如果您没有传递$ like变量,那么您的模型将如何搜索。

$like='any text' // this would be your keyword for which you are doing auto complete process, Like any name or anything.
$data['result'] = $this->search_model->autocomplete($like);