Pimcore:列出DateTime对象与提供的年份和月份匹配的对象

时间:2016-06-01 15:47:10

标签: datetime conditional-statements pimcore

我的代理机构正在为Pimcore上的博客部署构建过滤控件,我们正尝试按给定的YYYY-MM组合过滤帖子。我们对作者对象和主题对象进行了过滤。

以下是我们的控制器中应用过滤器和返回帖子的代码块...

// Pagination page...
$page = (int)$this->getParam("page") < 1 ? 1 : (int)$this->getParam("page");

// Results per page...
$rpp = (int)$this->document->getProperty( 'resultsPerPage' ) < 1 ? 1 : (int)$this->document->getProperty( 'resultsPerPage' );

// Return list of posts...
$list = new Object\BlogArticle\Listing();

// Apply author filter...
if( $this->getParam( 'filter-by' ) == 'author' ) {
    $list->setCondition( 'author LIKE ?', "%,".(int)$this->getParam( 'author' ).",%" );
}

// Apply category filter...
if( $this->getParam( 'filter-by' ) == 'category' ) {
    $list->setCondition( 'categories LIKE ?', "%,".(int)$this->getParam( 'category' ).",%" );
}

// This isn't working!
if( $this->getParam( 'filter-by' ) == 'archive' ) {
    $list->setCondition( "DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%m') = ".$list->quote( $this->getParam( 'archive' ) ) );
}

// Order by date...
$list->setOrderKey( "date" );
$list->setOrder( $this->document->getProperty( 'resultsSort' ) == 'asc' ? 'asc' : 'desc' );

// Apply pagination values...
$list->setLimit( $rpp );
$list->setOffset( ( $page - 1 ) * $rpp );

// Do it!
$this->view->blog = $list->getObjects();

$this->getParam( 'archive' )等于2016-06的某些内容。 Zend DateTime对象绑定到date列。

我查看了Pimcore文档,但我找不到任何关于如何查询对象的DateTime字段的信息。

1 个答案:

答案 0 :(得分:1)

你的方法似乎完全有效,它应该有效。日期函数名称中只有一个错误。它应该是 FROM_UNIXTIME 而不是FROMUNIXTIME。