Skip to content

Instantly share code, notes, and snippets.

@slav123
Created September 4, 2012 23:19
Show Gist options
  • Save slav123/3627945 to your computer and use it in GitHub Desktop.
Save slav123/3627945 to your computer and use it in GitHub Desktop.
pagination
/**
* pobieramy liste produktow
*
* @param integer $start od rekordu
* @param integer $limit ilość wyników
* @param integer $category_id id kategorii
*
* @return void
*/
public function products($start = 0, $limit = NULL, $category_id = NULL)
{
$this->load->model('product_model');
$this->load->library(array('pagination2', 'img'));
if (! is_null($limit))
$this->session->set_userdata('limit', intval($limit));
if (! $this->session->userdata('limit'))
$this->session->set_userdata('limit', 0);
$limit = $this->session->userdata('limit');
$this->data['segment'] = array('start' => intval($this->uri->segment(3)), 'limit' => intval($this->uri->segment(4)));
//$this->uri->segment(n)
if ($category_id > 0)
$this->data['title'] = $this->data['categories'][$category_id]['name'] . ' WAŚ';
else
$this->data['title'] = _('Lista produktów');
$this->data['pr'] = $this->product_model->get_products($start, $limit, 1, $category_id);
// jezeli jest kategoria, musi byc inny base url dla paging2
if (! is_null($category_id)) {
$config['base_url'] = $this->uri->segment(1) . "/" . $this->uri->segment(2) . '/';
} else {
$config['base_url'] = base_url() . 'index/products/';
}
$config['total_rows'] = $this->data['pr']['total'];
$config['per_page'] = $limit;
unset($this->data['pr']['total']);
$this->data['icond'] = $this->home_model->get_icons_desc();
$this->data['icond'][3] = substr($this->data['icond'][3], strpos($this->data['icond'][3], ' '));
$this->data['icond'][4] = substr($this->data['icond'][4], strpos($this->data['icond'][4], ' '));
if ($limit > 0 && $this->session->userdata('q') == FALSE) {
$this->pagination2->initialize($config);
$this->pagination2->next_link = $this->lang->line('next_page');
$this->pagination2->prev_link = $this->lang->line('prev_page');
$this->pagination2->ls = $this->lang->line('number_page');
}
// tablica z filtrem
$this->data['filter'] = $this->session->userdata('filter_product');
if (! $this->data['filter']) $this->data['filter'] = array('attributes' => array());
// ostatnio wybrana kategoria po lewej
$this->data['group_category'] = $this->session->userdata('group_category');
if (! $description = $this->cache->get('description_' . $this->lg)) {
$description = _('Nasza oferta ');
foreach ($this->data['categories'] as $category) {
$description .= $category['name'] . ' ';
}
$this->cache->save('description_' . $this->lg, $description, 3600);
}
$this->data['description'] = $description;
$this->load->view('products', $this->data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment