Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
$page and $current_page in Pagination
  • Hi.

    Just migrate to 1.4 and everything works fine except a pagination. I made changes as mentionned in the Doc and I encountered one tiny problem. If I click on page 3 and higher, or the next button nothing happens. I stay stuck on page 1 or 2.

    I solve this problem by adding one line but i don't understand why it's working with this change.

    My code : http://scrp.at/bVR

    I had to add this line in my controller to make things work :

    [code]$this->pagination['current_page'] = $page +1;[/code]

    Sorry to disturb you with a problem already solved, but something bother me with $current_page, $page and $num_links.

    Any idea ?

  • HarroHarro
    Accepted Answer
    You're doing a $page-- first, which is not needed. So remove that, and remove the +1.
  • Thx Harro, even thought it wasn't the purpose of my question.

    I just don't understand why I have to affect $page to $pagination['current_page']. With the previuous version it wasn't necessary besause the Pagination class was using its property uri_segmets to get the page number.

    Anyway, thank you for your job.
  • It still does that, have you set the uri_segment correctly?

    It defaults to 3, which is a URI like  "/controller/method/<pagenumber>".
  • ilNotturnoilNotturno
    Accepted Answer
    I'll post you a pagination that I use in every part of my website:

        public function action_index() {
            // Create a pagination 
            $pagination = \Pagination::forge('pagination', array(
                'pagination_url' => 'blog/index/',
                'total_items' => Model_Content::find()->where('published', 1)->count(),
                'per_page' => 10,
                'uri_segment' => 3,
                'num_links' => 5,
            ));
            
            // Get contents based on pagination
            $contents = Model_Content::find()
                    ->where('published', 1)
                    ->order_by('id', 'desc')
                    ->offset($pagination->offset)
                    ->limit($pagination->per_page)
                    ->get();
            
            \Theme::instance()->set_partial('content', 'public/nvblog/index');
        }

    If you look that, isn't necessary to insert the page value in the method body, it is automatically taken by the pagination class.
    The only things you have to do is to be sure that the link "pagination_url" is equal to (uri_segment - 1).

    In my case I have 2 segment ('blog' and 'index') and the page number wil be the third.

    Hope this will help you.

  • Thanks ilNotturno.

    I wasn't takign the good pagination_url because i forgot index in my declaration ans so the uri_segment wasn't good.

    I understand now why i had to specify current_page to make my solution works.

    Everything's clear now... for the moment.

  • You are welcome :-].

Howdy, Stranger!

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

In this Discussion