Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Pagination only works with the first 2 pages.
  • Pagination only works with the first 2 pages.

      All next pages are not displayed when clicking on links pager.


    My code;
    $view = View::forge('empresa/index');
               // Create a pagination
            $pagination = \Pagination::forge('pagination', array(
                'pagination_url' => \Uri::base(false) . 'empresa/index',
                'total_items' => Model_Empresa::find()
                                                    ->where('activa', "1")
                                                    ->count(),
                'per_page' => 5,
                'uri_segment' => 2,
                'num_links' => 5,
            ));
           
            // Get contents based on pagination
            $contents = Model_Empresa::find()
                ->where('activa', "1")
                  ->order_by('preciodesde', 'ASC')
                ->rows_offset(\Pagination::get('offset'))
                ->rows_limit(\Pagination::get('per_page'))
                ->get();
           
            // Set templates variables
                $data['pagination'] = $pagination;
                $data['content'] = $contents;
                $data['orden'] = 0;

                $data['regsitros'] = Model_Empresa::find()
                                                        ->where('activa', 1)
                                                        ->count();
          $this->template->title = "empresas";
          $this->template->content = View::forge('empresa/index', $data, False);
  • You should try with 'uri_segment' => 3
  • Yes, I've tried from the start and nothing,
    I modified the values ​​to test.
    Works Page button 1 and 2, the rest of the pages do nothing

    the url changes. but the results are not changed, 
  • I'm not sure of this, but maybe change

    \Pagination::get('offset')  by $pagination->offset
    and
    \Pagination::get('per_page')  by $pagination->per_page

    What version of FuelPHP are you using ? 

    Now in the 1.4,  Pagination class works with instance.

  • You can still use the static methods, which work on the default instance.

    I use this, and it works fine:
            // set pagination information
            \Pagination::instance()->uri_segment = 4;
            \Pagination::instance()->per_page = \Config::get('application.pagination', 20);
            \Pagination::instance()->total_items = Model\Person::count();
            \Pagination::instance()->pagination_url = \Uri::create('mymodule/people/all');

            // content for this action
            \Theme::instance()->set_partial('content', 'people/index')
                ->set('people', Model\Person::find()
                                        ->order_by('surname', 'ASC')
                                        ->rows_offset(\Pagination::instance()->offset)
                                        ->rows_limit(\Pagination::instance()->per_page)
                                        ->get());
    And then in the view:
    echo Pagination::instance()->render();

Howdy, Stranger!

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

In this Discussion