I would like to ask kindly someone to help me with this issue in my CakePHP 4.2.4 web app.
I have public function display() in my MenuCell class, which fetches data from database Menus (id, link_name, controlle, action, date, date_modified). Based on the database Table, I want to generate side navigation links in ascending order, i.e.
Menu
A …
B …
C …
D …
E …
I paginate data from the database as follows:
public function display()
{
$this->loadModel('Menus');
// Create a paginator
$paginator = new Paginator();
$results = $paginator->paginate($this->Menus, ['order' => ['Menus.name' => 'asc']]);
$this->set('menuitems', $results);
}
Nevertheless, result is that variable $menuitems is sorted according to the id key in database table, i.e. my Menu is ordered as follows:
Thank you dirk for your reply and thank you Zuluru for asking for additional information. Maybe my question will be clearer after reading my attempt to fix the issue below.
I tested to set $public variable according to dirk answer but this approach works only when I call the view using menus controller, i.e. /myapp/menus/sidemenuview/ When I try to sort items of the list in a Cell, it does not work. Here is the output as well as source code for comparison:
Maybe, its a bug or maybe parameters of the $public variable are transfered via URL somehow and this is the cause, why the sorting does not work for Cell. Please could someone chek this?
Thank you for your interest, Zuluru. Answer is no, the database with menu items is made manually and I want to fetch all data from second, third and fourth column. Nevertheless, I found solution, its in the cakephp Cookbook.
For everyone with similar problem, the solution is in images below (i slightly modified font in sidemenuview.php, so it looks differently, view files are attached):
Where I was going with my question is that, if you want all the menu options to be loaded, then the paginator is not something you should be using at all. You should just do a find and get all the results.