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

XF 2.0 whats wrong with my code ?

JustinHawk

Active member
#1
well the only issue i'm having that the pagination links are not coming as i want so can anyone help me to fix that and tell me what wrong i'm doing

code in php file
PHP:
public function actionTest(ParameterBag $params)
    {
    $user = $this->assertViewableUser($params->user_id);
        $visitor = \XF::visitor();
        $Repo = $this->repository('XF:Thread');
        $finder = $Repo->jtest($user);

        if (!$visitor->hasPermission('general', 'jtest'))
        {
            return $this->noPermission();
        }

        $total =  $finder->total();
        $page = $this->filterPage();
        $perPage = $this->options()->jtestoption;

        $this->assertValidPage($page, $perPage, $total, 'members/test', $user);
        $this->assertCanonicalUrl($this->buildLink('members/test', $user, ['page' => $page]));

        $testarray = $finder->limitByPage($page, $perPage)->fetch();

        $viewParams = [
            'testarray' => $testarray,
            'page' => $page,
            'perPage' => $perPage,
            'total' => $total,
        'user' => $user
        ];
....
code in template for page nav

Code:
            <xf:pagenav page="{$page}" perpage="{$perPage}" total="{$total}"
                        link="members/test" data="{$user}"
                        wrapperclass="block-outer-main" />
the problem is i want links to be like this

localhost/index.php?members/admin.1/test&page=2
but it gives
localhost/index.php?members/admin.1/page-2/test

so can anyone her help ?
 

Chris D

XenForo developer
Staff member
#2
You most likely need to add your own route to handle this, specifically.

If you look at the existing members route, you will see the following as the "Route format":
Code:
:int<user_id,username>/:page
The inclusion of the /:page bit tells the route system to represent the page number as part of the route itself.

That's what gives the profile URL page numbers a slightly friendlier appearance:
Code:
https://xenforo.com/community/members/chris-d.11388/page-2
vs:
Code:
https://xenforo.com/community/members/chris-d.11388/?page=2
We've actually already done something similar in XF2 with the followers and following pages, and this is essentially what you will need to do. Here's what the "followers" page URLs look like:
Code:
https://xenforo.com/community/members/chris-d.11388/followers/page-3
Your new route would look something like this:
1506605576157.png

You may also need to access the page number with $params->page (similar to actionFollowers() in the Member controller).