【问题标题】:codeigniter pagination, sending parameters between functionscodeigniter 分页,在函数之间发送参数
【发布时间】:2013-07-15 19:38:49
【问题描述】:

我遇到了分页和 codeigniter 的问题。我有一个来自女巫的 quick_searh 视图,我正在将信息提交给索引控制器函数,并在那里设置分页并调用 quick_search 方法来获取我想要的数据。它只是行不通。我花了超过 5 个小时重写这些方法,甚至从 quick_search 开始,然后传递给 index 函数,但没有任何效果,请帮忙。

    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);
    }
}

快速搜索功能:

    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";

数据已显示,但我没有看到其中的分页 .. 甚至当我想更改 url 以进行分段时,它说我没有任何数据。

视图是这样的:

<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();

【问题讨论】:

    标签: php codeigniter pagination


    【解决方案1】:

    你不能使用 $this->pagination->create_links();视图中的方法。

    使用 $data['pagination'] = $this->pagination->create_links();在加载视图之前的控制器中 并在视图中回显 $pagination

    希望这会对你有所帮助。

    【讨论】:

      【解决方案2】:

      根据您的搜索变量,您可以使用:

      $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');
      
      /*pagination start*/
      $this->load->library('pagination');
      $config['base_url']         = base_url().'index.php/index/lawyer/'.$lawyer_name.'/kanzlei/'.$kanzlei.'/area_of_expertise/'.$area_of_expertise.'/post_code/'.$city.'/page/';
      $config['total_rows']       = $this->model->count_all_results();    ###implement this function to count all the vodeos as per the search variables, just use the same function as "quick_search" but without the limit clause
      $config['per_page']         = count($result);;
      $config['uri_segment']      = 10;
      $config['next_link']        = 'Next';
      $config['prev_link']        = 'Prev';
      $config['cur_tag_open']     = '<span class="active_page">';
      $config['cur_tag_close']    = '</span>';
      $this->pagination->initialize($config);
      /*pagination end*/
      

      【讨论】:

      • 感谢您的回答,我已经实现了您的想法,但它仍然不起作用,我还在base_url() 中添加了 post_code 和 city。向模型添加了一个新函数,该函数返回行数,但是现在当我单击 2. 页面时,这实际上是更改基本 url 的时间,并且我收到一个错误,因为该页面不存在:-/我做了有什么问题吗?
      • 我不好更改这一行,上面的答案是缺少控制器名称,我假设您的控制器名称是search$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
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多