Welcome Guest, Not a member yet? Register   Sign In
Pagination / Reduce footprint / Advice
#1

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?

PHP Code:
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
Reply


Messages In This Thread
Pagination / Reduce footprint / Advice - by MoFish - 12-06-2014, 03:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB