Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
404 error on pagination
  • Hello all,

    I'm facing an issue with pagination class using fuelphp 1.6

    Following the documentation, I prepared my code like this  :

    A model function is returning $tmp which is the records that I count and pass to the configuration (tested and works)

    then I build my confi like this :

     $config = array(
                'pagination_url' => \Fuel\Core\Uri::base(false).'searchprofile',
                'total_items'    => count($tmp),
                'per_page'       => 4,
                'uri_segment'    => 2,
                'num_links'      => 5,
                'show_first'      => true,
                'show_last'      => true,
                'current_page'   => 1 
            );

    Then I create the pagination :

      $pagination = Pagination::forge('mypagination', $config);
     
    then I call a model function that returns the records properly as an array with offset and limit (tested and works, correct records are sent back)

     $data['defaultSearchProfiles'] = Model_Search::DefaultSearch($latitude ,$longitude, $distance ,\Fuel\Core\Session::get('userId'), $pagination->per_page, $pagination->offset);
     
    Then I render it, and call my view
     $data['pagination'] = $pagination->render();
     $this->template->content = View::forge('searchprofile/index', $data);
     
     
    In my view I display my records and i added the pagination with
     
     <?php echo $pagination ; ?>
     
    The result is, that my records and the pagination appear correctly, but only on the view without pagination segment. If I click on link #1 then the url shows ...../controler# and the view does not change. If I click on link #2, the url shows ..../controler/2 but the content is error 404, that is the same for all following pages.
     
    So it seems that I am doing exactly what the documentation is showing but can't get the links to have a normal behavior.
     
    What do you think I am doing wrong ?
     
    Thank you very much in advance for your help.

    Philippe
  • HarroHarro
    Accepted Answer
    I think your segment count is wrong.

    2 is usually where the method name is: /controller/method/action/<number>, so it should probably be 4, unless your uri has a diifferent structure.
  • Hello Harro,

    Thank you for you answer.

    I tried what you said without success.
    My controller name is searchprofile and my method is action_index. I tried to display the usi segment with count(uri::segement), this is 1. So in my understanding the correct segment value is 2 right ?

    Any other idea ?

    Thank you once again Harro

  • HarroHarro
    Accepted Answer
    No.

    If your URL is http://yourhost/searchprofile/index/page/1, then the uri_segment number is 4 (the page number is the 4th segment in that URL).

    In the Uri class, you see the segments passed to the controller, after resolving the controller. Pagination doesn't have a clue about controllers, it only deals with complete URI's.
  • Ok, thanks.

    'pagination_url' => \Fuel\Core\Uri::base(false).'searchprofile/index/page' gives no error 404 anymore but clicking on each page gives first page each time

    Same with 'pagination_url' => \Fuel\Core\Uri::base(false).'searchprofile/index',
  • Any more idea ? I'm stuck :(
    Thanks
  • HarroHarro
    Accepted Answer
    you've set the current page hardcoded to 1 in your pagination definition?
  • Actually....yes :(

    It was not the only thing to correct anyway. The pagination url needed to be that way :
    'pagination_url' => \Fuel\Core\Uri::base(false).'searchprofile/index/page/',
    instead of
    'pagination_url' => \Fuel\Core\Uri::base(false).'searchprofile',

    Thank you once again Harro for your kind support.

Howdy, Stranger!

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

In this Discussion