作为 CAKEPHP 初学者,我面临这个问题,如果这是一个非常简单的问题,我很抱歉。
我的数据库中的一个表中有一个 TIMESTAMP 字段,但我只想显示数据库中的月份和日期。由于有一个 mysql 函数 MONTHNAME() 和 DAYOFMONTH(),这对我来说是解决方案,但我想知道如何使用 paginate() 函数来做到这一点,如下所示。
在我的 LogController index() 中,我有以下代码;
$this->Log->recursive = 0;
$this->paginate = array(
'limit' => 10,
'order' => array(
'Log.id' => 'desc'
));
$this->set('logs',$this->paginate());
在我的 View/Logs/index.ctp 中,我有;
$i = 0;
foreach ($logs as $log):
echo h($log["Log"]["time"]);
我该怎么做?
最佳答案
将字段添加到分页函数中。
$this->paginate = array(
'limit' => 10,
'order' => array(
'Log.id' => 'desc'
),
'fields' => '*,MONTHNAME(Log.time)');
关于cakephp - 如何在cakephp中的$this->paginate()中传递自定义mysql查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070461/