Aswathy S
Aswathy S

Reputation: 729

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);
        }

Upvotes: 0

Views: 719

Answers (3)

Paul Beck
Paul Beck

Reputation: 2685

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

Upvotes: 2

Paul Beck
Paul Beck

Reputation: 2685

Always forgetting the same: Do you "return $query->execute();" ? ;-)

Upvotes: 1

René Pflamm
René Pflamm

Reputation: 3354

Please check if your storagePid settings for you own extension is set to the pid of your tx_news folder:

plugin.my_extkey {
  persistence {
    storagePid = xxx
  }
}

Otherwise you can say your query it should not respect the storage pid:

$query = $this->createQuery();
$querySettings = $query->getQuerySettings();
$querySettings->setRespectStoragePage(false);
$query->setQuerySettings($querySettings);

Upvotes: 1

Related Questions