1
votes

I'm using paginator on CakePHP 2. I already sent the paginator from the controller to the view. If I debug the next and prev methods of the paginator this is what I get:

debug($this->Paginator->next(null, null, array('class' => 'disabled')));
'<span class="next"><a href="/Project/Controller/method/127151/page:2" rel="next"></a></span>'

I need to do the pagination on a frame in the same page, so when the user click next or previous page, not all the page refresh, just the frame that I'm using to display the data. I will do that using the $.post method of Jquery, but I need the URL that the prev and next show within the href, not all the span and the other elements, something like $this->Html->url provides.

Someone know how can I retrieve the URL from the previous and next methods of the paginator?

3

3 Answers

1
votes

You can try This way

$nextPage=$this->params->paging['MODELNAME']['nextPage']; // for users table MODELNAME User 
'<span class="next"><a href="/Project/Controller/method/127151/page:'.$nextPage.'" rel="next"></a></span>'
0
votes

I found a way to get this resolved using the DOM methods of PHP:

    $htmlNext = $this->Paginator->next(null, null, array('class' => 'disabled')); //gets paginator next HTML tag
    $domNext = new DOMDocument();
    $domNext->loadHTML($htmlNext);
    $tagsNext = $domNext->getElementsByTagName('a');
    $theLinkNext = "";
    foreach ($tagsNext as $tag) 
    {
        $theLinkNext = $tag->getAttribute('href');
    }

Now on the $theLinkNext variable you have the URL for the next page, then you just call $.post of Jquery and use the URL to get the data:

var loadNotesPage = "<?php echo $theLinkNext ?>";
$.post(loadNotesPage, function (data) {
    $('#loading-notes').html(data);
});
0
votes

$this->Paginator->url() By default returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript). you can check out cakephp 2.x documentation here i hope this helps someone