Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Something wrong with pagination
  • My code:

    function action_index()
        {
            $count = count(\Model_Advert::find('all'));

            $config = array(
                'pagination_url' => 'http:/sales/advertlist/index/',
                'total_items'    => $count,
                'per_page'       => 5,
                'uri_segment'    => 3,
            );

            $pagination = Pagination::forge('mypagination', $config);

            $adverts = \Model_Advert::find()
                ->order_by(array('begintime'=>'desc'))
                ->limit($pagination->per_page)
                ->offset($pagination->offset)->get();
            $this->template->set('adverts', $adverts, false);
        }


    In the View:
          <?php  echo Pagination::instance('mypagination')->render(); ?>

    The first page is displayed well with pagination. But click on the second page gives 404 error because the second link is advertlist/2 but not advertlist/index/2. Can you tell me why it happens?
  • OMG, I found my mistake. http:/sales/advertlist/index/ - here should be doubleslash after http:
  • Somthing wrong with paging. On the second and on the third pages the same elements are shown (there are only three pages at all). URL is different, but on the third page (URL ends on 3) style of pager is like on the second page.

    If I enter 4-th, 5-th page etc (manually) - the second page is displayed.

    Where should I look?
  • U can remove "http://" in pagination_url, and i think uri_segment is 4, no ?
  • I use local server and "sales" - is my working directory... I tried to delete http://sales but nothing changed.
  • Ok, the uri_segment is 3 in this case.

    Here is an example i use for my application :

        public function action_index() {
           
            // Pagination config
            $config = array(
                'pagination_url' => 'backend/log/index/',
                'total_items' => Model_Log::count(),
                'per_page' => 10,
                'uri_segment' => 4,
                'num_links' => 10,
                'show_first' => true,
                'show_last' => true,
            );
            $pagination = Pagination::forge('logs', $config);
            $this->data['logs'] = Model_Log::find('all', array(
                'order_by' => array('created_at' => 'DESC'),
                'limit' => $pagination->per_page,
                'offset' => $pagination->offset
                ));
            $this->data['pageTitle'] = "Gestion des logs";
            $this->data['logsPagination'] = $pagination->render();
            
            Theme::instance()->set_partial('content', 'backend/log/index');
        }

Howdy, Stranger!

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

In this Discussion