简体   繁体   English

设置为隐藏在后端TYPO3中时在控制器中检索对象

[英]Retrieving an object in controller when set hidden in backend TYPO3

I am using the news extension for managing news message for my website. 我正在使用新闻扩展名来管理我网站的新闻消息。 Some of the news items are disabled in the backend. 一些新闻项在后端被禁用。 A user has an url with the id of news object and it will trigger an action in my controller 用户有一个带有新闻对象ID的网址,它将触发我的控制器中的操作

I am trying to get my news object like this 我正在尝试让我的新闻对象像这样

$news = $this->newsRepository->findByUid($id);

This will return a NULL because it's disabled/hidden in the backend. 这将返回NULL因为它在后端被禁用/隐藏。 When i switch it back to enable. 当我切换回启用。 It will return my object nicely. 它将很好地返回我的对象​​。

I tried it with the following function in my newsRepository 我在newsRepository中使用以下功能尝试了它

public function findHiddenByUid($uid) {

            $query = $this->createQuery();
            $query->getQuerySettings()->setRespectSysLanguage(FALSE);   
            $query->getQuerySettings()->setRespectStoragePage(FALSE);
            $query->getQuerySettings()->setEnableFieldsToBeIgnored(array('disable')); 
            return $query
            ->matching(
            $query->equals('uid', $uid)
            )
                ->execute()
                ->getFirst();

 }

But this will also return a NULL . 但这也会返回NULL

Is the function wrong, am I missing some settings? 该功能是否错误,我是否缺少某些设置? I am using TYPO3 7.6 我正在使用TYPO3 7.6

Check out the findByUid I am using in the news extension: 在新闻扩展中查看我正在使用的findByUid

public function findByUid($uid, $respectEnableFields = true)
{
    $query = $this->createQuery();
    $query->getQuerySettings()->setRespectStoragePage(false);
    $query->getQuerySettings()->setRespectSysLanguage(false);
    $query->getQuerySettings()->setIgnoreEnableFields(!$respectEnableFields);

    return $query->matching(
        $query->logicalAnd(
            $query->equals('uid', $uid),
            $query->equals('deleted', 0)
        ))->execute()->getFirst();
}

By calling ->findByUid(123,false) will also return hidden objects. 通过调用->findByUid(123,false)也将返回隐藏的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM