Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination class - nightmare :(
  • I am having immense difficulty in trying to get the pagination class to print html, which conforms to the pagination markup of twitter boostrap. http://twitter.github.com/bootstrap/components.html#pagination The largest problem, is trying to get the inactive links inside li tags, which the pagination class does not seem to want to do. $config = array(
    'per_page' => $limit,
    'total_items' => $count,
    'uri_segment' => $segment,
    'pagination_url' => $pagination,
    'template' => array(
    'wrapper_start' => '',
    'wrapper_end' => '',
    'page_start' => '<li>',
    'page_end' => '</li>',
    'previous_start'=> '',
    'previous_end' => '',
    'previous_mark' => '',
    'next_start' => '',
    'next_end' => '',
    'next_mark' => '',
    'active_start' => '',
    'active_end' => ''
    ),
    ); <div class="row"> <div class="span8"> <div class="pagination">
    <ul>
    <li><?php echo Pagination::prev_link('Previous'); ?></li>
    <?php echo Pagination::page_links(); ?>
    <li><?php echo Pagination::next_link('Next'); ?></li>
    </ul>
    </div> </div> </div>
  • it's one of the reasons the current pagination class is deprecated. HTML should be part of the app, not of a core class. if you check the code in the admin interface of our depot project (https://github.com/fuel/depot) you can see how I solved it (the admin interface uses bootstrap).
  • I am just struggling with the same issue. @WanWizard: I have checked your implementation in depot repository but your implementation is not compatible with bootstrap implementation... I also use Twitter bootstrap for my admin section but the output with your Pagination implementation gives me this: http://dl.dropbox.com/u/1207859/pagination.png. How does this render for you? Another question regarding your pagination implementation in depot. What are you doing with $page variable here ($page--) and where do you use it?
    public function action_index($page = 1)
    {
        // make sure $page contains something usefull
        if ( ! is_numeric($page) or $page < 1)
       {
            $page = 1;
       }
    
       // pages internally are zero offset
       $page--;
    ...
    

    BTW: I have found Twitter Bootstrap friendly Pagination class here: http://pastebin.com/31HpZQGd.
  • For Depot I try to use as much FuelPHP solutions as possible, as it serves as an example too. The admin controller code is the one generated by oil, I assume that bit of code was generated. I would have to look at it. The current pagination class is a nightmare, and the reason it is deprecated in it's current form. For 2.0, we're going to redesign it so all layout related setup is done in your application, and not in the class. We haven't decided if we're going to backport it once it is ready.
  • Well its not that bad, with a little modifications you can have it work with bootstrap easily... And if you want it easily to write your own layout! And the code you have with $page variable, I think is useless since you dont use this var anyway!
  • How to properly set up pagination links so that when you have search functionality with HTTP get so that pagination generated links use GET parameter? For example I have search box that send GET request to action search:
    admin/users/search/search?search=test
    

    In action search my pagination is set and I would like links to be generated like (example for page 2):
    admin/users/search/2?q=test
    

    Thanks!
  • to OP just use the custom class that was written for twitter, it works great. Jume, the pagination class doesn't use any post or get data, it just looks at the URI and finds the right segment for next & previous. I was having a hell of a time with this too when i had extra optional variables I wanted to pass, the solution for me was to set any params besides page as session vars in the before method.
    public function before($data = null) {
    
            parent::before();
    
    
            if (Input::get('filter')) {
    
                if (Input::get('filter') == 'everything') {
                    Session::delete('filter');
                    Session::delete('filter_id');
                } else {
                    Session::set('filter', Input::get('filter'));
                    Session::set('filter_id', Input::get('id'));
                }
            }
            if (Input::get('sort')) {
                Session::set('sort', Input::get('sort'));
            }
        }
    

    so in your case maybe pick up the query as post data
  • Bperin yes I figured that out. I also solved it by setting session variable for search string and now I have solution I wanted! Thanks.
  • Just a quick fix for anyone having the same issue, as I needed params for my pagination aswell In core/classes/pagination.php, I changed this line:
    static::$current_page = (int) \URI::segment(static::$uri_segment); to this
    static::$current_page = (int) static::$uri_segment; This way, when you setup the actions in the controller you just specify whatever variable will hold the current page, something like:
    'uri_segment' => \Input::get('page'),

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion