Search code examples
cakephppaginatorcakephp-2.5

Cakephp-2.5 next navigation url without html code


How can I get next navigation url without html code ?

$this->Paginator->next();
//output
<a href="xxx">Next</a>

I just need url only.


Solution

  • The paginator helper itself doesn't support that, the least HTML'd return value (tag => false) is a simple anchor element, so you'll have to build the URL on your own, which is pretty simple tough.

    What you need is the current page number, this can be retrieved via PaginatorHelper::params(), the page key in the returned array holds the current page.

    All you have to do then is add 1 to it, and pass a URL array with the key page and the new page number as its value to Router::url() and you'll get the URL for the next page:

    $params = $this->Paginator->params();
    $url = array(
        'page' => $params['page'] + 1
    );
    echo Router::url($url);
    

    ps. you might want to check whether there is actually a next page using PaginatorHelper::hasNext()

    if($this->Paginator->hasNext())
    {
        // ...
    }