我想检索自今天起1年内的文章。基本上,我想将我网站的文章部分分成新文章(1年内)和存档文章(1年以上)。如何更改以下语句以确保发生这种情况?
$articles = $this->Article->find(
'all',
array(
'fields' => array(
'Article.title',
'Article.body',
'Article.slug',
'Article.id',
'Article.image',
'Article.created'
),
'order' => 'Article.created DESC',
'conditions' => array(
'Article.created >' => //What do I need to add here
)
)
);
对于存档文章我会做同样的事情,但条件不同:
$archived_articles = $this->Article->find(
'all',
array(
'fields' => array(
'Article.title',
'Article.body',
'Article.slug',
'Article.id',
'Article.image',
'Article.created'
),
'order' => 'Article.created DESC',
'conditions' => array(
'Article.created <' => //What do I need to add here
)
)
);
谢谢,
答案 0 :(得分:3)
'Article.created <' => date("Y-m-d H:i:s", strtotime("-1 year"));