Friday, March 30, 2012

Re: paginator with user defined page sizes...

Nobody that can help?

On Tuesday, March 27, 2012 10:23:12 AM UTC+2, Thomas wrote:


Am Montag, 26. März 2012 17:01:49 UTC+2 schrieb 100rk:
Form using GET method, dropdown named 'limit' or 'show' with onchange = 'this.form.submit();' - see pagination settings 'paramType' and 'maxLimit'.

http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html#pagination-with-get-parameters

Works - nearly :-)

I added the form and select elements to my template:

index.ctp:

<?php
    echo $this->Form->create(FALSE);
    echo $this->Html->link('Add Post', array('controller' => 'posts', 'action' => 'add'));
    echo '<br><br>'.$this->Paginator->numbers(array('before'=>'Pages: '));

    $options = array( 2 => 'two', 4 => 'four');
    echo '&nbsp;Show '.$this->Form->select('recordlimit', $options, array('value'=>2, 'empty' => FALSE, 'onChange'=>'this.form.submit();')).' records per page.';
?>
 
And the following code in PostsController.php:

<?php
class PostsController extends AppController {
    public $name = 'Posts';
    public $helpers = array('Html', 'Form');
    public $components = array('Session');
    public $paginate = array(
            'paramType' => 'querystring',
            'limit' => 2,
            'order' => array(
                'Post.title' => 'asc'
            )
        );   

    function beforeFilter(){
        $this->paginate['limit'] = intval($this->request->data('recordlimit'));       
    }
   
In the debugger, I can now see that the "limit" option of the paginator gets set to 4 if I select option "four", but I only get a single record and a total of 5 pages (one record per page) shown after this.

I also don't know how I can access the current limit of the paginator from the view to set the correct option in the select.

Also, the direct page links always look like this (limit = 1):

http://localhost/cakephp/posts?/posts=&page=2&limit=1

I know I'm nearly there - but CakePHP is quite complex and the learning curve steep for me.

I urgently need results so any help is appreciated very much.

Thanks!
Thomas

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: