Swap Sort in Cakephp 3.x

In cakephp 3.x I cannot do paginate order in search

This is my controller:

//AgentsController.php public function show() { $agents = $this->Agents->find() $this->set('agents', $this->paginate($agents)); } 

And here is part of my view

 //show.ctp <!-- ....... --> <table class="table table-striped"> <thead> <tr> <th> <?php echo $this->Paginator->sort('full_name', 'Nome', array('escape' => false)); ?> </th> <th> <?php echo $this->Paginator->sort('username', 'Email', array('escape' => false)); ?> </th> <th> <?php echo $this->Paginator->sort('regions', 'Regioni', array('escape' => false)); ?> </th> </tr> </thead> <!-- ....... --> 

Where am I mistaken?

+2
php cakephp
source share
2 answers

Paginator will block any attempt to sort by column that does not exist in the primary table of the query you are using. In this case, you have 2 options. The first option is to change the sorting links to indicate to the cake that the column belongs to the linked table:

 <?php echo $this->Paginator->sort('Users.full_name', 'Nome'); ?> 

Or you can specify this in the component to allow sorting by a specific set of columns:

 $this->paginate = ['sortWhitelist' => ['full_name', 'username']] 
+10
source share

Try:

 $this->paginate = ['sortWhitelist' => ['full_name','username','regions'],'limit' => 3]; 

This will also set the pagination limit.

-one
source share

All Articles