【问题标题】:Missing argument 1 for search_model::autocomplete(),search_model::autocomplete() 缺少参数 1,
【发布时间】:2015-07-23 08:08:06
【问题描述】:

这是控制器 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

这个问题有什么解决办法?

【问题讨论】:

  • 您需要点击复选标记接受答案
  • @Amy 将 $like 变量传递给你的 $data['result'] =$this->search_model->autocomplete();

标签: php ajax codeigniter


【解决方案1】:

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

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

因为在你使用的模型文件中

public function autocomplete($like) {

【讨论】:

  • @Santy 'YOUR_LIKE_VARIABLE 是什么意思??
  • 要在模型文件中传递的变量。我的意思是$like
【解决方案2】:

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

在你的控制器中

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

【讨论】:

  • $like = "匹配词"; // 用你的值替换它; $data['result'] =$this->search_model->autocomplete($like);
【解决方案3】:

如果您不传递 $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);

【讨论】:

    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多