Topic: Pagination inside widgets

 
User
Gravatar
Joined: 2011-10-06
Posts: 1
Hi,

is there any way to use CI's pagination inside a widget?

I've tried to do it (see code below) but when I click one of the links (http://domain.tld/particulares/12), I'm redirected to 404
The widget is inside a content page.

This is my widget code

public function run($options) { $this->load->model('articulos/product_m'); $category_id = $options['category_id']; $this->load->library('pagination'); $config = array(); $config['base_url'] = current_url(); $config['total_rows'] = $this->product_m->count_all_by_category($category_id); $config['per_page'] = 12; $config['uri_segment'] = 2; $this->pagination->initialize($config); $offset = $this->uri->segment( $config['uri_segment'] ); $products = $this->product_m->get_all( $config['per_page'] , $offset , $category_id ); return array( 'products' => $products, 'pagination' => $this->pagination->create_links() ); }
 
 
Admin
Gravatar
Joined: 2009-07-16
Posts: 823
You cannot use pagination in a Widget, because a widget is just some data in a block on a page. A widget does not have multiple pages.

You'll need to do this as a custom module instead.
 
 
User
Gravatar
Joined: 2011-08-09
Posts: 12
You could use a jQuery UI plugin to 'fake' pagination within a widget.