Hello, I'm a beginner at cake.I have a question because I am stuck with the query settings.
Here's what you want to do:
I am writing a custom query as follows:
$this->paginate=[
'limit' = > 20,
'order'=>array('date'=>'desc'),
'group' = > ['date' = > 'month(date)' ]
];
$datasList=$this->paginate($this->model);
The results are as follows:
Date
November 02, 2016 (smallest date)
October 01, 2016 (smallest date)
September 21, 2016 (smallest date)
Date
November 05, 2016 (date is up to date)
October 05, 2016 (date is up to date)
September 30, 2016 (date is up to date)
·Whether or not the latest date can be displayed successfully just by setting the paginate.
·Is there any other better way?
Thank you for your cooperation.
php mysql cakephp
The solution is as follows:
Implemented in the query builder
To set max(date), get query and set select.
$query=$this->Table->find();// query retrieval
$query->select([]
Specify 'date'=>$query->func()->max('date')//max(date)
]);
$this->paginate=[
'limit' = > 20,
'order'=>array('date'=>'desc'),
'group' = > ['date' = > 'month(date)' ]
];
$datasList=$this->paginate($query);
Reference
https://teratail.com/questions/48872
http://book.cakephp.org/3.0/ja/orm/query-builder.html#sql
I couldn't solve myself.
356 I want to create an array of sequences from "1" to a specified number.
356 Unity Virtual Stick Does Not Return to Center When You Release Your Finger
341 Understanding the Meaning of mpm prefork Settings
342 Memory layouts learned in theory don't work out as expected when actually printed as addresses.
© 2023 OneMinuteCode. All rights reserved.