pagination snippet anyone?

edited March 2014 in Modules
can anyone give an example of pagination implementation in fuel?
i have found bits n pieces of information, somewhere i saw that $pagination is available but how n where.

Comments

  • edited 11:10PM
    FUEL uses the Pagination library from CI:
    http://ellislab.com/codeigniter/user-guide/libraries/pagination.html

    The fuel/modules/fuel/controllers/module::list_items method uses it and passes a $pagination variable to the view.
  • edited 11:10PM
    But how do I use this in Fuel
    for example, I have this view

    $list_where = array('featured' => 'yes'); $model = 'projects_model'; $projects = fuel_model($model, array('find' => 'all','limit' => 10 ,'where' => $list_where)); ?> <?php if (!empty($projects)) : ?> <?php foreach($projects as $project) : ?> <h5><?php echo $project->heading; ?></h5> <p> <?php echo $project->description; ?> </p> <?php endforeach; ?> <?php endif; ?>
  • edited 11:10PM
    This looks to be a front end page correct? If so, you'll want to do something like this:
    $CI =& get_instance(); $CI->load->library('pagination'); $CI->load->model('projects_model'); $limit = 10; $offset = $CI->input->get('offset'); $total = $CI->projects_model->record_count(); $projects = $CI->projects_model->find_all($list_where, '', $limit, $offset); $config['base_url'] = 'projects'; $config['total_rows'] = $total; $config['uri_segment'] = 2; $config['per_page'] =$limit; $config['query_string_segment'] = 'offset'; $config['page_query_string'] = TRUE; $config['num_links'] = 5; $CI->pagination->initialize($config); $links = $this->pagination->create_links(); echo $links;
  • edited March 2014
    Yes I am finally finishing up the front-end.

    I was getting this error,

    Message: Undefined property: MY_Loader::$pagination

    so updated this part

    $links = $this->pagination->create_links(); to $links = $CI->pagination->create_links();
    and it worked. thanks.
Sign In or Register to comment.