Codeigniter 控制器仅将第一个参数传递给模型
大家好,stackoverflow.com的人们,这是我的第一个问题,温柔一点:) 就像问题一样,我的控制器只发送4个参数中的第一个。如果我替换论点的位置,他将再次只发送第一个论点。 这是为了搜索,如果它是重要的。 无论如何,这是代码: 控制器:Codeigniter 控制器仅将第一个参数传递给模型,codeigniter,search,model,controller,arguments,Codeigniter,Search,Model,Controller,Arguments,大家好,stackoverflow.com的人们,这是我的第一个问题,温柔一点:) 就像问题一样,我的控制器只发送4个参数中的第一个。如果我替换论点的位置,他将再次只发送第一个论点。 这是为了搜索,如果它是重要的。 无论如何,这是代码: 控制器: public function groups($question = NULL, $city = NULL , $country = NULL, $area = NULL){ if ($question == NULL && $cit
public function groups($question = NULL, $city = NULL , $country = NULL, $area = NULL){
if ($question == NULL && $city == NULL && $country == NULL && $area == NULL) {
$groups = $this->ModelSt->getGroups();
} else {
$groups = $this->ModelSt->search($question, $city , $country, $area);
}
$data['groups'] = $groups;
$data['controller'] = "UserSt";
$data['method']= "search";
$this->loadView($data, "groups.php");
}
}
建模师:
public function search($question, $city , $country, $area) {
$query = "SELECT * FROM `group` WHERE `status`='1' ";
if($question && !empty($question)){
$query .= " AND (`name` LIKE '%".$question."%' OR `desc` LIKE '%".$question."%')";
}
if($city && !empty($city)){
$query .= " AND (`city` LIKE '".$city."')";
}
if($country && !empty($country)){
$query .= " AND (`country` LIKE '".$country."')";
}
if($area && !empty($area)) {
$query .= " AND (`area` LIKE '". $area ."')";
}
$result = $this->db->query($query);
$result = $result->result_array();
return $result;
}以数组形式发送参数,如下所示:
$this->ModelSt->search(
array(
'question' => $question,
'country' => $country,
'city' => $city,
'area' => $area
)
);
您的型号:
public function search($post)
{
$question = isset($post['question']) && !is_null($post['question']) && !empty($post['question']) ? $post['question'] : NULL;
$city = isset($post['city']) && !is_null($post['city']) && !empty($post['city']) ? $post['city'] : NULL;
$country = isset($post['country']) && !is_null($post['country']) && !empty($post['country']) ? $post['country'] : NULL;
$area = isset($post['area']) && !is_null($post['area']) && !empty($post['area']) ? $post['area'] : NULL;
$this->db->select('name, city, country, area');
$this->db->from('group');
$this->db->where('status', 1);
$this->db->group_start();
/**
* Question is not null
*/
if($question != NULL)
{
$this->db->group_start();
$this->db->like('name', $question);
$this->db->or_like('desc', $question);
$this->db->group_end();
}
/**
* City is not null
*/
if($city != NULL)
$this->db->like('city', $city);
/**
* Country is not null
*/
if($country != NULL)
$this->db->like('country', $country);
/**
* Area is not null
*/
if($area != NULL)
$this->db->like('area', $area);
$this->db->group_end();
$this->db->order_by('name', 'asc');
return $this->db->get()->result();
}
好的,在一段时间内不涉及代码中的任何内容之后,变量1、3和4将被传递给模型,但变量2不会。没有碰任何东西,它只是开始工作。前几天,Codeigniter的“upload”库也发生了同样的事情,40分钟后它就不工作了,然后无缘无故地开始工作。。。我想我得等可变$city通过。谢谢你的回答
public function search($post)
{
$question = isset($post['question']) && !is_null($post['question']) && !empty($post['question']) ? $post['question'] : NULL;
$city = isset($post['city']) && !is_null($post['city']) && !empty($post['city']) ? $post['city'] : NULL;
$country = isset($post['country']) && !is_null($post['country']) && !empty($post['country']) ? $post['country'] : NULL;
$area = isset($post['area']) && !is_null($post['area']) && !empty($post['area']) ? $post['area'] : NULL;
$this->db->select('name, city, country, area');
$this->db->from('group');
$this->db->where('status', 1);
$this->db->group_start();
/**
* Question is not null
*/
if($question != NULL)
{
$this->db->group_start();
$this->db->like('name', $question);
$this->db->or_like('desc', $question);
$this->db->group_end();
}
/**
* City is not null
*/
if($city != NULL)
$this->db->like('city', $city);
/**
* Country is not null
*/
if($country != NULL)
$this->db->like('country', $country);
/**
* Area is not null
*/
if($area != NULL)
$this->db->like('area', $area);
$this->db->group_end();
$this->db->order_by('name', 'asc');
return $this->db->get()->result();
}