TYPO3 6.2流体分页无法按预期工作

时间:2015-05-14 06:09:34

标签: typo3 fluid extbase typo3-6.2.x typo3-4.5

我的TYPO3 6.2(从TYPO3 4.5升级)流体分页显示所有项目而不是5项。

我的存储库方法:

public function getRandomLocation($iLimit)
{
    $query = $this->createQuery();
    $result = $query->statement("Select * FROM      tx_sfel_domain_model_ttblocationsproduktegruppen WHERE hidden = 0 AND deleted = 0 AND logo != '' ORDER BY uid LIMIT 0, ".$iLimit." ");
    return $result->execute(); 
}

我的控制器代码:

$aSResultsLocations = $this->tTBLocationsProdukteGruppenRepository->getRandomLocation($iLimit);
$this->view->assign('aSResultsLocations', $aSResultsLocations);

我的模板:

    <f:widget.paginate objects="{aSResultsLocations}" as="aSResultsLocationss" configuration="{itemsPerPage: 5, insertAbove: 1 insertBelow: 1}"> 

                <f:for each="{aSResultsLocationss}" as="aSResultsLocation">
                     .................

                     //Getting all the items instead of 5 items.

                </f:for>
    </f:widget.paginate> 

TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController.php indexaction()我得到了以下结果。

代码:

$itemsPerPage = (int)$this->configuration['itemsPerPage'];

$query = $this->objects->getQuery();
$query->setLimit($itemsPerPage);
if ($this->currentPage > 1) {
     $query->setOffset((int)($itemsPerPage * ($this->currentPage - 1)));
}
$modifiedObjects = $query->execute();

我从这里得到的价值观是:

$ itemsPerPage:5

$query : Select * FROM tx_sfel_domain_model_ttblocationsproduktegruppen WHERE hidden = 0 AND deleted = 0 AND (jahr = '13' OR jahr = '14' OR jahr = '15') AND logo != '' ORDER BY uid LIMIT 0, 26

$ modifiedObjects count = 26

但我需要'$ modifiedObjects count'为5。

我认为以下内容不适合我的查询对象,

$query->setLimit($itemsPerPage);
$query->setOffset((int)($itemsPerPage * ($this->currentPage - 1)));

我认为这个问题与我在分页中使用的查询对象有关。 如何为TYPO3 6.2流体分页创建查询对象

请帮帮我。

1 个答案:

答案 0 :(得分:0)

为解决上述问题,我以extbase查询格式重建了查询。在typo3 6.2.x中,paginate不能用于查询语句,因此我们需要将其转换为extbase查询格式。

我重建的查询格式是,

$constraints = array(); 
$subConstraints = array(); 
$query = $this->createQuery(); 

foreach($PublicationYears as $year) 
     $subConstraints[] = $query->equals('jahr', $year); 

$constraints[] = $query->logicalOr($subConstraints); 

$constraints[] = $query->logicalNot( $query->equals('logo', '') ); 

$query->matching($query->logicalAnd($constraints)); 

$query->setLimit((integer)$iLimit); 

$Result = $query->execute();