在CodeIgniter上过滤和分页 [英] Filter and pagination on CodeIgniter

查看:198
本文介绍了在CodeIgniter上过滤和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CodeIgniter的新人,但我想问一下分页和过滤。
我做了他们,他们彼此工作伟大,但我有两个页面,过滤器和分页。他们给我一些错误。
- 当我点击过滤器,url是这样: company / components / all / names_of_filters
所以过滤器工作在uri段(4)。
============================================== =========================但是当我加载分页它显示我
company / components / all / pagination ,所以过滤器崩溃与分页。我声明uri段(5)加载分页,但同样的事情。这个想法是,过滤器正在从数据库改变,它是一个动态部分。我如何在
$ conf [base_url] =(company / components / all /...../)声明它,并在这些破折号中连接一个函数更改名称过滤器? -------------------------------------------------- -------------------------------------------------- -----
*有没有方法吗? *
Best:)

I'm new at CodeIgniter, but I want to ask about pagination and filtering. I did them and they works great aside from each other, but I have two pages with filters and pagination too. They gives me some errors. -When I click Filter, the url is like this: company/components/all/names_of_filters so the filters works at uri segment(4). =========================================================================But when I load pagination it shows me company/components/all/pagination so the filters crashes with pagination. I declared uri segment(5) for loaded the pagination but the same thing. The idea is that the filter is changing from database and it is an dynamic part. How can I declare it on $conf[base_url]=(company/components/all/...../) and put in those dashes an function that is concatenate an function that changes names filter?! --------------------------------------------------------------------------------------------------------- *Has any method or not? * Best :)

推荐答案

控制器 b
$ b

Controller

    $this->load->library('pagination');
    $pagination_config['base_url'] = base_url('/webs/webs1/all/');
    $pagination_config['total_rows'] = $this->model_m->count_all();
    $pagination_config['per_page'] = 2;
    $pagination_offset = $this->uri->segment(5);
    $this->pagination->initialize($pagination_config);
    $data['pagination_links'] = $this->pagination->create_links();
    //end

    //fetch categories from the database
    $data['categories'] = $this->model_m->get_categories();     
    $categoryID = $this->uri->segment(4);
    if($categoryID == null){
        redirect('backend/subcategories/all/filterAll');
    }
    if(!isset($categoryID) || ( $categoryID == "filterAll" )) {
        $data['subcategories'] = $this->model_m->get_all_subcategories();
    } else {
        $data['subcategories'] = $this->model_m->get_by_category($categoryID);
    }
    $data['selected_category'] = $categoryID;

    $data['view'] = $this->load->view($view,$data,true);
    $this->load->view($viewlayout,$data);

MODEL

public function get_by_category($id){
    $query = $this->db->get_where('items', array('prod_id' => $id));
    if ($query->num_rows() > 0) { return $query->result(); }
    return false;
}

public function get_all_subcategories($catID = NULL,$limit = NULL ,$offset = NULL ) {
    if(isset($catID) && is_int($catID)) {
        if(isset($limit) && isset($offset)){
            $result = $this->db->get_where('items',array('prod_id' => $catID),$limit,$offset);
            return $result->result();
        }
        $result = $this->db->get_where('items',array('prod_id' => $catID));
        return $result->result();
    }

    if(isset($limit) && isset($offset)){
        $result = $this->db->get('items',$limit,$offset);
        return $result->result();
    }
    $result = $this->db->get('items');
    return $result->result();
}

public function count_all() {
    return $this->db->get('items')->num_rows();
}

这篇关于在CodeIgniter上过滤和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆