You need to make pagination on the page, not the same as on the other pages.

The main pagination has this pattern

$this->Paginator->templates([ 'nextActive' => '<li class="pag-next"><a rel="next" href="{{url}}">{{text}}</a></li>', 'nextDisabled' => '<li class="pag-next disabled"><a href="" onclick="return false;">{{text}}</a></li>', 'prevActive' => '<li class="pag-prev"><a rel="prev" href="{{url}}">{{text}}</a></li>', 'prevDisabled' => '<li class="pag-prev disabled"><a href="" onclick="return false;">{{text}}</a></li>', 'number' => '<option value="{{url}}">{{text}}</option>', 'current' => '<option selected="selected" value="{{url}}">{{text}}</option>' ]); 

You need to create a new template, and that it is applied only on the pages where it is needed.

And one more problem that the smarty template engine is used in the project.

  • smarty problem? oo What is the difficulty then? you pass the templates by parameter, pass others where appropriate. In general, it seems to me that you are overly wise. I duck as it was not necessary to rewrite the standard templates paginator. - teran
  • @teran I pass these parameters with src / view / SamrtyView.php. How can I transfer them from another place? - Sanya

1 answer 1

Maybe a little off topic answer, but in my, maybe not great, practice of using CakePHP I did not have to rewrite explicitly the paginator templates. To display pagination, I use a single-smarty template.
So let's say we chose the data:

  $st = TableRegistry::get('SomeTable'); $query = $st->find()->where([ ... ])->orderDesc('id'); $items = $this->paginate($query); $this->set('items', $items); 

in the src\templates\MyController\index.tpl output src\templates\MyController\index.tpl list the elements and add the smarty-pagination template:

 {foreach $items as $i} <li>{$i.title|escape}</li> {/foreach} {include "../Common/_paginate.tpl"} 

it is necessary to arrange the output of pagination in different ways - draw several different templates _paginateX.tpl or pass different options there.

My pagination pattern looks like this:

 {if $paginate_options|default:null} {$this->Paginator->options($paginate_options)} {/if} <div class="paginator text-right"> <ul class="list-unstyled list-inline"> {if $this->Paginator->hasPrev()} {$this->Paginator->prev("«")} {/if} {$this->Paginator->numbers()} {if $this->Paginator->hasNext()} {$this->Paginator->next("»")} {/if} </ul> </div> 

maybe this, of course, somewhat violates the concept of the helper itself, but gives complete freedom in generating pagnination. But if it is necessary to change the pagination drastically, it is easier to do this than to customize the templates. Such a technique of patterns for the states of the paginator (used in cakephp and given in the question), unfortunately, somewhat contradicts the MVC model, and brings the presentation somewhere to the controller level, or where else it is configured.

  • thanks for the answer. But this is really not quite right. A fragment of my code with src / view / SamrtyView.php. It is unlikely to violate the agreement. And the problem is that $this->Paginator->numbers() generates an <option value="{{url}}">{{text}}</option> . If I change it in SamrtyView.php, it will change on the whole site, and I only need on some sections - Sanya
  • @SanyaLavrechko Well, as for me, the task of the view in this case is to process the desired template format, in this case tpl. Xs whether to load the view with other functionality. In general, you can install the same in the controller. Either pass a parameter to a view and, based on it, either replace templates in the view class or not. - teran
  • I generally think that jnyjcbntkmyj mvc, v would be a tpl-template rather than a SmartyView class. Therefore, the hash of html and pkhp code is bad, as always, and there is no exception. So in the paginator part. and in part of the form-helper templates used in cakephp, the solution I don’t really like is somewhat crutch, in my opinion. - teran
  • as another variation, you can apply these settings directly in the tpl-template, that is, just before calling the paginator in the template add the {$this->Paginator->templates(...)} call, and this part can also be rendered In a separate tpl and include where required. - teran