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

pagenav with search

Discussion in 'XenForo Development Discussions' started by TheJP, Feb 8, 2014.

  1. TheJP

    TheJP Member


    I would like to have a pagenav (<xen:pagenav>) in a template which shows search results. I'm struggling to set it up so that it still shows the search results when i go to the next page.

    In the template I have the following two possibilities:
    <xen:pagenav link="teams" linkdata="{$search}" page="{$page}" perpage="{$perpage}" total="{$totalTeams}" />
    <xen:pagenav link="teams" page="{$page}" perpage="{$perpage}" total="{$totalTeams}" />
    The upper produces these links:
    The lower produces these links:
    Is there a way to combine the two, so I get the following links?
    My current route
    class LoLCompetition_Route_PrefixPublic_Teams implements XenForo_Route_Interface
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
    $action $router->resolveActionWithIntegerParam($routePath$request'team_id');
    $action $router->resolveActionAsPageNumber($action$request);
        public function 
    buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    $data && !empty($data['search'])){ $extraParams['search'] = $data['search']; }
    $action XenForo_Link::getPageNumberAsAction($action$extraParams);
    Important parts of the controller
    $options XenForo_Application::get('options');
    $perpage $options->lolcompetition_teams_perpage;
    $search $this->_input->filterSingle('search'XenForo_Input::STRING);
    $page $this->_input->filterSingle('page'XenForo_Input::UINT);
    $viewParams = array(
    'teams' => $this->_getTeamsModel()->getTeams(/*...*/),
    'perpage' => $perpage,
    'totalTeams' => $this->_getTeamsModel()->getTeamCount(/*...*/),
    'page' => $page
    $viewParams['search'] = array('search' => $search);
  2. Kerby

    Kerby Active Member

    I'll paypal 10$ for an answer that helps to get the solution ;)
    TheJP likes this.
  3. TheJP

    TheJP Member

    I found a solution which works for me on my own now.
    Do I get the 10$ now Kartus? ;P

    I will not post the complete solution here. I don't have time for such a huge post^^
    I will give a hint though. I used the following code in the template:
    <xen:pagenav link="teams" linkparams="{$search}" page="{$page}" perpage="{$perpage}" total="{$totalTeams}" />
    Kerby likes this.
  4. Aayush

    Aayush Well-Known Member

    For all those still wondering how to do something like this.
    1. Pass the a variable from the controller to the template. Just for the example let us name it $linkParams
    2. Make $linkParams an array of key-value pairs.
    $linkParams = [
    'search' => 'searchstring',
    'type' => 'google'
    3. Use it in the template like
    <xen:pagenav link="teams" linkparams="{$linkParams}" page="{$page}" perpage="{$perpage}" total="{$totalTeams}" />
    Now the URL should look like
    Kerby likes this.

Share This Page