如何在前端获取隐藏记录?想要获得隐藏记录然后将隐藏更改为0。
问问题
7818 次
3 回答
8
您可以为存储库中的单一方法进行此设置:
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 Some
*/
public function findHiddenByUid($uid): Some
{
$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
:
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(): void
{
// 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);
}
}
于 2015-12-04T10:59:53.837 回答
4
您可以使用Repository 的initializeObject方法,因此我们不必为 Repository 中的每个方法编写 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);
}
}
于 2015-12-04T12:41:30.530 回答
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();
}
}
于 2013-10-03T16:20:17.543 回答