[英]How do I solve this CodeIgniter's 'Too few arguments to function' error?
Good day,everyone, Please.大家好,拜托。 am new to CodeIgniter.., Actually,am try to write a search module script using inner join.
我是 CodeIgniter 的新手..,实际上,我尝试使用内部连接编写搜索模块脚本。 but I don't know what am not getting right.
但我不知道什么不对。
This is the error message: An uncaught Exception was encountered Type: ArgumentCountError这是错误消息:遇到未捕获的异常类型:ArgumentCountError
Message: Too few arguments to function Career_model::quick_search(), 0 passed in C:\xampp\htdocs\hue\application\controllers\Pages.php on line 69 and exactly 4 expected Message: Too few arguments to function Career_model::quick_search(), 0 passed in C:\xampp\htdocs\hue\application\controllers\Pages.php on line 69 and exactly 4 expected
Filename: C:\xampp\htdocs\hue\application\models\Career_model.php文件名:C:\xampp\htdocs\hue\application\models\Career_model.php
Line Number: 124行号:124
Backtrace:回溯:
File: C:\xampp\htdocs\hue\application\controllers\Pages.php Line: 69 Function: quick_search文件:C:\xampp\htdocs\hue\application\controllers\Pages.php 行:69 Function:quick_search
File: C:\xampp\htdocs\hue\index.php Line: 286 Function: require_once文件:C:\xampp\htdocs\hue\index.php 行:286 Function:require_once
This is my controller:这是我的 controller:
function quick()
{
if ($this->session->userdata('username')):
$session_data = $this->session->userdata('username');
$query = $this->db->query("select * from account where email='$session_data'");
$data = $query->result();
foreach ($data as $key => $value);
$this->form_validation->set_rules('gender','Gender', 'required');
$this->form_validation->set_rules('from','lowest age', 'required');
$this->form_validation->set_rules('to','highest age', 'required');
if ($this->form_validation->run() == FALSE):
$this->load->view('pages/search_result');
else:
$gender = $this->input->get_post('gender');
$from = $this->input->get_post('from');
$to = $this->input->get_post('to');
$country = $value->country;
//I suppose this is where the problem is coming from
if($this->Career_model->quick_search($gender,$from,$to,$country)):
$data = $this->session->set_flashdata('error','something went wrong...');
redirect('pages/search_result',$data);
else:
$result['data'] = $this->Career_model->quick_search();
redirect('pages/search_result',$result);
endif;
endif;
endif;
}
And here is the Model:这是 Model:
function quick_search($gender,$from,$to,$country)
{
$this->db->join("about" , "account.ref_id = about.user_id");
$this->db->where('gender',$gender);
$this->db->where('country',$country);
$this->db->where('age',$from);
$this->db->where('age <=',$to);
$query = $this->db->get('account');
return $query->result();
}
Thanks in advance...提前致谢...
The error is because you're not providing any parameters when you call your model in else condition(which expects 4 parameters).该错误是因为您在其他条件下调用 model 时没有提供任何参数(需要 4 个参数)。 I've written a possible solution for you, see if it helps.
我已经为你写了一个可能的解决方案,看看它是否有帮助。
Remove this code to the one below --将此代码删除到以下代码 -
// Remove this code
if($this->Career_model->quick_search($gender,$from,$to,$country)):
$data = $this->session->set_flashdata('error','something went wrong...');
redirect('pages/search_result',$data);
else:
$result['data'] = $this->Career_model->quick_search(); // this line is causing error because 0 parameters are passed.
redirect('pages/search_result',$result);
endif;
to至
// This is probably what you want ↓↓
$result = $this->Career_model->quick_search($gender, $from, $to, $country); // get the data once and then check if data empty or not
if(!empty($result)){ // success
$data['result'] = $result;
}else{ // fail
$this->session->set_flashdata('error','No data found');
}
redirect('pages/search_result',$data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.