CakePHP 1.3:如何使用 Find 只检索从今天起 12 个月内的文章
我想检索从今天起 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
)
)
);
谢谢,
I would like to retrieve articles that are within 1 year from the today's date. Basically, I would like to split the article section of my site into new articles (within 1 year) and archived articles (older than 1 year). How do I change the following statement to make sure this happens?
$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
)
)
);
I will do the same thing for archived articles but with different condition:
$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
)
)
);
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)