Search code examples
typo3typoscriptextbasetx-news

Got empty object when call news from my extension in TYPO3


I have to create an extension to filter the news. So I build an extension with news model. My model looks like

class News extends \GeorgRinger\News\Domain\Model\News
{        
}

I have to list all news from my extension. So I called the

$this->newsRepository->findAll();

From my controller.But it returns an empty object.So I write a custom function FilterNews() here is my code

$query = $this->createQuery();
$query->matching(
    $query->equals('uid', 1)
);
return $query->execute();

There is a news with uid = 1.But it returns empty. How can I access news?

I included the following function in my repository

     public function initializeObject() {
            $querySettings = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
            $querySettings->setRespectStoragePage(FALSE );
            $querySettings->setIgnoreEnableFields(TRUE);   
$querySettings->setEnableFieldsToBeIgnored(array('disabled','starttime'));
            $querySettings->setIncludeDeleted(FALSE);
            $querySettings->setRespectSysLanguage(FALSE);

            $this->setDefaultQuerySettings($querySettings);
        }

Solution

  • Another solution: Add table mapping to your model see this extension: https://github.com/Schweriner/tgm_lazynews/blob/master/ext_typoscript_setup.txt