1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pagination does not work

Discussion in 'XenForo Development Discussions' started by Hugilore111, May 11, 2016.

  1. Hugilore111

    Hugilore111 Member

    Hi
    I have not worked pagination
    tell me where the error

    Route
    Code:
    <?php
    class Example_Route_Prefix_Example implements XenForo_Route_Interface
    {
     
        public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
        {
            return $router->getRouteMatch('Example_ControllerPublic_Account', 'account/example', 'forums');
        }
       }
    Controller
    Code:
        $viewParams =array(
       
           
               'thingsPerPage'=>50,
               'page'=>5,
               'totalThings'=>10
             
            );
    template

    Code:
    <xen:title>Page navigation example{xen:helper pagenumber, $page}</xen:title>
    <xen:pagenav link="account/example" page="{$page}" perpage="{$thingsPerPage}" total="{$totalThings}" />
     
    Last edited: May 11, 2016
  2. wang

    wang Well-Known Member

    What is the code that you are using in your model and controller?
     
    Hugilore111 likes this.
  3. Hugilore111

    Hugilore111 Member

    Model
    Code:
        public function Example($Example,array $fetchOptions)
        {
            $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
         
            return $this->_getDb()->fetchAll($this->limitQueryResults('
                SELECT xf_example.*
                FROM xf_example_ex
                INNER JOIN xf_user ON xf_user.user_id = xf_example_ex.user_id
                WHERE (' . $Example . ') = xf_example_ex.id_ex
             ORDER BY xf_user.username DESC
            ', $limitOptions['limit'], $limitOptions['offset']
        ));
        }
    Controller
    Code:
    <?php
    class Example_ControllerPublic_Account extends XFCP_Example_ControllerPublic_Account
    {
     
     
        public function actionExample()
        {
    $thingsPerPage = XenForo_Application::get('options')->thingsPerPage;
    $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT));
    $Example = $ModelExample->Example($Example,array('perPage' => $thingsPerPage, 'page' => $page));
    $viewParams =array(
       
             
               'thingsPerPage'=>$thingsPerPage,
               'page'=>$page,
               'totalThings'=>count($Example)
             
            );
    return $this->_getWrapper(
                    'account', 'example',
                    $this->responseView('Example_ViewPublic_Account_Example', 'example',$viewParams)
                );
     
        }
     
  4. wang

    wang Well-Known Member

    You must create another function to count the things from your database table. Then you call it to the controller and register its variable. See the examples posted by Bob in that other thread that you posted about this.
     
    Hugilore111 likes this.

Share This Page