I would like to include a dropdown into an overview page that allows the user to select the paginator page size himself, e.g. 10, 25, 50, 100 items/page
But since there is no "form" or "submit" on the overview page, I don't know how I can get the value of the select input control.
Is there a CakePHP "standard" way to do something like this?
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'.
<?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):
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'.
> <?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):
I suggest you just wrap the dropdown in a form, use a submit on the
same page ($this->Form->create('Modelname', array('url' => $this-
>here));) to send the form to the same action you're in at this
moment.
In your controller use a RequestHandler-Part to get changes of the
dropdown and write them into a session variable. Then use a paginator
defintion directly within the controller, and set the limit of the
paginator to the value of the depending session-key.
That should be a 2-minute task, if you have any questions just ask, I
will post the code for you if you cannot get any further.
Hint:
To define the paginator from within an action (and not globally for a
whole controller), use the following code in your action:
> 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'.
> > 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):
Note the additional "cakephp" part, it looks as if $this->here returns a wrong URL
I have removed the 'url' definition which fixed that but I would like to understand the logic or idea behind this 'feature'
You also wrote:
In your controller use a RequestHandler-Part to get changes of the
> dropdown and write them into a session variable.
But I did not find out what a "RequestHandler-Part" might be or how to use a session from within the controller - I'm currently quite overwhelmed by the huge amount of classes, helpers, components etc. that CakePHP offers - plus I'm also struggling with the transition from my current language (Xbase++, which is some xBase dialect) to PHP - especially the heavy use of multiply nested arrays is quite confusing to me.