Cakephp:每天随机录制一次

时间:2015-05-19 06:20:03

标签: cakephp random

如何才能让随机结果仅在24小时后发生变化?

 $random = $this->Post->find('first',array(
        'conditions' => array(
            'Post.active'=>1,
        ),
        'order' => 'rand()',
    ));
    $this->view($random['Post']['id']);
    $this->render('view');

1 个答案:

答案 0 :(得分:0)

您可以尝试根据当前日期为rand()函数使用种子。

$random = $this->Post->find('first', array(
    'conditions' => array(
        'Post.active' => 1,
    ),
    'order' => 'rand(' . date('Ymd') . ')',
));

或者,缓存结果并每天刷新一次缓存。