我有分页和codeigniter的问题。我有一个从女巫的quick_searh视图,我将这些信息提交给索引控制器函数,并在那里设置分页并调用quick_search方法来获取我想要的数据。它只是没有用。我花了5个多小时重写这些方法,甚至从quick_search开始,然后传递给索引函数,但没有任何工作,请帮助。codeigniter分页,功能之间发送参数
public function index(){
// search parameters config
$lawyer_name = $this->input->post('lawyer_name');
$kanzlei = $this->input->post('kanzlei');
$area_of_expertise = $this->input->post('area_of_expertise');
$post_code = $this->input->post('post_code');
$city = $this->input->post('city');
$result = $this->quick_search(
$this->uri->segment(3),
$lawyer_name,
$kanzlei,
$area_of_expertise,
$post_code,
$city);
if(isset($result)){
// pagination config
$this->load->library('pagination');
$this->load->library('table');
$config['total_rows'] = count($result);
$config['base_url'] = 'http://localhost/anwalt/index.php/search/index';
$config['per_page'] = 5;
$config['num_links'] = 5;
$this->pagination->initialize($config);
$data['search_result_array'] = $result;
$data['main_content'] = 'pages/quick_search_results';
$this->load->view('templates/home_body_content', $data);
}
}
的quick_search功能:
public function quick_search($offset, $lawyer_name, $kanzlei, $area_of_expertise, $post_code, $city){
// no input in the quick search
if(empty($lawyer_name) && empty($kanzlei) && empty($area_of_expertise)
&& empty($post_code) && empty($city))
{
$result = 'nothing';
} else {
$this->load->model('quick_search_model');
$result = $this->quick_search_model->get_search_results(
$offset,
$lawyer_name,
$kanzlei,
$area_of_expertise,
$post_code,
$city
);
}
return $result;
}
的SQL是这样的:
$sql = "SELECT users.user_id, users.canonical_name, first_name, last_name, city, phone_number, kanzlei
from users
inner join user_normal_aos
on users.user_id = user_normal_aos.user_id
inner join normal_areas_of_expertise
on user_normal_aos.normal_areas_of_expertise_id = normal_areas_of_expertise.normal_areas_of_expertise_id
where ".implode(" AND ", $where);
if(empty($offset)){
$offset = 0;
}
$sql = $sql." LIMIT ".$offset.", 4";
的数据显示,但我没有看到拼版在那里..甚至当我想改变分割它的网址说我没有任何数据。
的看法是这样的:
<h1>Quick search results</h1>
<?php
if($search_result_array == "nothing"){
echo "<h3>You havent inputed anything</h3>";
} else {
echo $this->table->generate($search_result_array);
}
echo $this->pagination->create_links();
谢谢你的回答,我已经实现了你的想法,但它无效,我也在'base_url()'中添加了post_code和city。为模型添加了一个新的函数,返回行数,但现在当我点击2.页面时,这实际上是基础url更改的时间,并且我得到一个错误seking这个页面不存在: - /我做了有问题 ? – kalafun
我不好改变这一行,上面的答案是缺少控制器名称,我假设你的控制器名称是'搜索':'$ config ['base_url'] = base_url()。'index.php/search/index/lawyer /'.$ lawyer_name。'/ kanzlei /'.$ kanzlei。'/ area_of_expertise /'.$ area_of_expertise。'/ post_code /'.$ city。'/ page /';' –
是的,我有这样的:'' $ config ['base_url'] = base_url()。'index.php/search/index/lawyer /'.$ lawyer_name。'/ kanzlei /'.$ kanzlei。'/ area_of_expertise /'.$ area_of_expertise。'/ post_code/'。$ post_code。'/ city /'.$ city。'/ page /';'但它仍然不起作用。当我点击搜索按钮时,网址就像'../ index.php/search/index' – kalafun