CakePHP 1.3:如何使用 Find 只检索从今天起 12 个月内的文章

发布于 2025-01-08 06:42:46 字数 1065 浏览 5 评论 0原文

我想检索从今天起 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-15 06:42:46
'Article.created <' => date("Y-m-d H:i:s", strtotime("-1 year"));
'Article.created <' => date("Y-m-d H:i:s", strtotime("-1 year"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文