ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CI Paging | Bit too bloated | Need advice

December 06, 2014 4:43pm

Subscribe [1]
  • #1 / Dec 06, 2014 4:43pm

    MoFish

    1 posts

    Hi,

    I’m fairly new to CI but have been loving it so far! I currently have a ‘staff’ listing with pagination which is working as expected. However feel my code is a little ‘bloated’ every time i want to initialize paging in my controllers. I’m looking for a way to minimize the footprint in my controllers to maybe a couple lines of code, but am unsure on the best way to do this. I hoped someone would be able to point me in the right direction.

    As mentioned above, the code works perfectly - but seems long winded

    1)

    After a bit of scanning around online, it said that using a config file may help. I therefore have a ‘pagination.php’ in the configs folder which does a little bit of customization to how the paging control will render. This seems to work well, and I’m fairly happy with that part.

    2)

    In my controller, I have the following few lines of code (which seems too much for me) to set up the paging control. I’m looking for a way to minimize this down to a couple lines ideally. What way would you suggest doing this?

    public function index(){
    $data['title'] = 'Staff Listing';
    
    /* PAGING */
    $config['base_url'] = '/staff/index';
    $config['per_page'] = '1';
    $config["total_rows"] = $this->staff_model->count();
    $config["num_links"] = round($config["total_rows"] / $config["per_page"]);
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment($this->config->item('uri_segment'))) ? $this->uri->segment($this->config->item('uri_segment')) : 0;
    $data["staff"] = $this->staff_model->get_all($config["per_page"], $page);
    $data["paging"] = $this->pagination->create_links();
    
    $this->load->view('staff/index', $data);
    }

    Thanks for your time.

    MoFish

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases