CakePHP Elements on the Helper Page

How to generate from the page directory a list of drop-down lists with elements on the page? The default value is 20 elements per page, I want to get something like this:

Show <select> <option value="10">10</option> <option value="25">25</option> <option value="50">50</option> <option value="100">100</option> </select> entries 

http://jsfiddle.net/HkWuH/

+4
source share
4 answers

As mentioned in @BigToach, I added this to a method in my controller

 $this->paginate = array( 'paramType' => 'querystring', 'limit' => 30, 'maxLimit' => 100 ); 

and add the following code to my view

 $limit = $this->params->query['limit']; $options = array( 5 => '5', 10 => '10', 20 => '20' ); echo $this->Form->create(array('type'=>'get')); echo $this->Form->select('limit', $options, array( 'value'=>$limit, 'default'=>20, 'empty' => FALSE, 'onChange'=>'this.form.submit();', 'name'=>'limit' ) ); echo $this->Form->end(); 
+7
source

The results on the page are controlled by the "limit" parameter in the paginate array

 <?php $this->paginate = array( 'paramType' => 'querystring', 'limit' => 30, ); ?> 

You can override this by setting a limit as the value of the query string. Example:

 ?limit=40 

From there, you just need to create a drop-down list that changes the url when they select the number on the page.

You can also implement maxLimit so that users do not change this value to an extremely large number.

+2
source

(This is really just a Warthel4578 comment, but I don’t have enough comments to comment ... I just wanted to share this advice for those who are faced with the same question that I had with this solution)

Thus, I continued to receive the error "Undefined index: limit" (in the line that sets $limit = $this->params->query['limit']; ) when the page of my paginated results was loaded initially, although after changing the values ​​of the drop-down list and the updated pagination results error is gone.

Instead of $limit = $this->params->query['limit']; I had to use this in my view:

 $page_params = $this->Paginator->params(); $limit = $page_params['limit']; 
+2
source

I think you could use:

 // Use the defaults. echo $this->Paginator->limitControl(); 

Additional information on

https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-limit-selectbox-control

+1
source

Source: https://habr.com/ru/post/1488221/


All Articles