我的代理机构正在为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字段的信息。
答案 0 :(得分:1)
你的方法似乎完全有效,它应该有效。日期函数名称中只有一个错误。它应该是 FROM_UNIXTIME 而不是FROMUNIXTIME。