Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination problem
  • I asked this in Stack but seems no one out there.any way.

    I'm working on a project with Fuel. I created a pagination , first page has data truly in it but when I click on other pages , uri changes but page never refresh and it doesn't show other pages. codes:

    code in Controller :

               $config = array(
    'pagination_url' => 'http://localhost/body-app/public/app/list/',
    'total_items' => 12,
    'per_page' => 3,
    'uri_segment' => 5,
    // or if you prefer pagination by query string
    //'uri_segment' => 'page',
    );
    $pagination = Pagination::forge('mypagination', $config);

    $data['example_data'] = DB::select('*')
    ->from('bodies')
    ->limit($pagination->per_page)
    ->offset($pagination->offset)
    ->execute()
    ->as_array();
    $data['pagination'] = $pagination;
    $view=View::forge('app/list',$data);

    and my foreach in View is something like this :

          <?php foreach($example_data as $per) { 

    echo $per['name'] ;
    } ?>

    and finally code to show pagination :

    <?php echo Pagination::instance('mypagination')->render();  ?>
  • I don't see anything immediately wrong.

    Load the page, the add a

    var_dump($data);
    exit;

    before your VIew in the confroller, and click on another page link.

    Is the contents of the pagination object correct? Did it query the correct records?
  • I did that. in the  first page again it retrieved right data but when I changed the uri nothing happened and same thing was showing and previous data also . (I have 6 record in database but it's only retrieving first 3 ones in every page in fact it doesn't refresh the only url changes)

    I had array of 'example _data' and pagination.Here is pagination:

    'pagination' => 
    object(Fuel\Core\Pagination)[21]
    protected 'config' =>
    array (size=12)
    'current_page' => null
    'offset' =>
    int 0
             'per_page' => 
    int 3
    'total_pages' => int 2
    'total_items' => int 6
    'num_links' => int 5
    'uri_segment' => int 5
    'show_first' => boolean false
    'show_last' => boolean false
    'pagination_url' => string 'http://localhost/body-app/public/app/list' (length=41)
    'link_offset' => float 0.5
    'calculated_page' => int 1
    protected 'template' =>
    array (size=25)
    'wrapper' => string '<div class="pagination">
    {pagination}
    </div>
    ' (length=46)
    'first' => string '<span class="first">
    {link}
    </span>
    ' (length=37)
    'first-marker' => string '&laquo;&laquo;' (length=14)
    'first-link' => string ' <a href="{uri}">{page}</a>
    ' (length=29)
    'first-inactive' => string '' (length=0)
    'first-inactive-link' => string '' (length=0)
    'previous' => string '<span class="previous">
    {link}
    </span>
    ' (length=40)
    'previous-marker' => string '&laquo;' (length=7)
    'previous-link' => string ' <a href="{uri}" rel="prev">{page}</a>
    ' (length=40)
    'previous-inactive' => string '<span class="previous-inactive">
    {link}
    </span>
    ' (length=49)
    'previous-inactive-link' => string ' <a href="#" rel="prev">{page}</a>
    ' (length=36)
    'regular' => string '<span>
    {link}
    </span>
    ' (length=23)
    'regular-link' => string ' <a href="{uri}">{page}</a>
    ' (length=29)
    'active' => string '<span class="active">
    {link}
    </span>
    ' (length=38)
    'active-link' => string ' <a href="#">{page}</a>
    ' (length=25)
    'next' => string '<span class="next">
    {link}
    </span>
    ' (length=36)
    'next-marker' => string '&raquo;' (length=7)
    'next-link' => string ' <a href="{uri}" rel="next">{page}</a>
    ' (length=40)
    'next-inactive' => string '<span class="next-inactive">
    {link}
    </span>
    ' (length=45)
    'next-inactive-link' => string ' <a href="#" rel="next">{page}</a>
    ' (length=36)
    'last' => string '<span class="last">
    {link}
    </span>
    ' (length=36)
    'last-marker' => string '&raquo;&raquo;' (length=14)
    'last-link' => string ' <a href="{uri}">{page}</a>
    ' (length=29)
    'last-inactive' => string '' (length=0)
    'last-inactive-link' => string '' (length=0)
    protected 'raw_results' =>
    array (size=0)

  • HarroHarro
    Accepted Answer
    I doesn't pick up the page number from the URI, which suggests the uri_segment value is wrong.

    uri segments aren't counted on the raw URL, the are counted on the internal URI which starts with the controller. So assuming your controller is App::action_list(), the uri_segment must be 3, not 5.
  • Thanks a lot that u always help people.
    yeah problem was with segment. firstly I changed that to 3 but it didn't work again cause it goes to :
    which is absolutley wrong , so I changed the value of uri_segment to:
           'uri_segment'    => 'list'

    and works now.
    when it value was 5 uri was like :

    but when changed that to string became :
    which is right one.
    seems it's better to use string type values when using uri_segment.

  • I depends.

    it should not be a problem using a segment number, I've never used anything else. Perhaps it has something to do with the fact you have both a folder name and "public" in the URL, which indicates some non-standard rewrite rules.

    I would have to test that to see what exactly the problem is.

Howdy, Stranger!

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

In this Discussion