EXTBASE:如何获取隐藏记录

时间:2013-10-03 16:16:12

标签: repository typo3 hidden-field extbase

如何在前端获取隐藏记录?想要隐藏记录然后将隐藏更改为0。

3 个答案:

答案 0 :(得分:8)

您可以在存储库中为单个方法进行此设置:

<?php
namespace Vendor\ExtensionName\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\Repository;

/**
 * Some Repository
 */
class SomeRepository extends Repository
{    
    /**
     * Find a record by uid even if it is hidden or deleted
     *
     * @param  int $uid
     * @return object
     */
    public function findHiddenByUid($uid) {
        $query = $this->createQuery();

        // Here you enable the hidden and deleted Records
        $query->getQuerySettings()
            ->setIgnoreEnableFields(true)
            ->setIncludeDeleted(true);

        // Your query
        $query->matching($query->equals('uid', $uid));
        return $query->execute()->getFirst();
    }
}

或整个存储库。这包括您从TYPO3\CMS\Extbase\Persistence\Repository继承的方法:

<?php
namespace Vendor\ExtensionName\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;

/**
 * Some Repository
 */
class SomeRepository extends Repository
{
    /**
     * Always return hidden and deleted records from this Repository
     */
    public function initializeObject() {
        // Load the querySettings
        $querySettings = $this->objectManager->get(Typo3QuerySettings::class);

        // Ignore hidden and deleted records
        $querySettings
            ->setIgnoreEnableFields(true)
            ->setIncludeDeleted(true);

        // Set your settings as default for the entire Repository
        $this->setDefaultQuerySettings($querySettings);
    }
}

答案 1 :(得分:3)

重点是在'querySettings'中禁用'respectEnableFields'属性。您可以在您的存储库中执行此操作:

class SomeRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

    public function findHiddenByUid($uid) {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectEnableFields(FALSE);
        $query->matching($query->equals('uid', $uid));
        return $query->execute()->getFirst();
    }
}

答案 2 :(得分:3)

您可以使用 initializeObject 存储库方法,这样我们就不必为存储库中的每个方法编写querySettings

class SomeRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

    /**
     * initialize querySettings
    */
    public function initializeObject() {
        $querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');

        // Get Hidden and Deleted Records
        $querySettings->getQuerySettings()->setIgnoreEnableFields(true);

        //Disable Storage pid
        $querySettings->setRespectStoragePage(FALSE);
        $this->setDefaultQuerySettings($querySettings);
    }
}