TYPO3: repository->findAll() not working

2019-03-01 06:47发布

I am building an extension with a backend module. When I call the findAll() method it returns a "QueryResult" object.

I tried to retrieve objects with findByUid() and it does work.

I set the storage pid in the typoscript:

plugin.tx_hwforms.persistence.storagePid = 112

I can also see it in the typoscript object browser.

I also added this to my repository class:

public function initializeObject()
    {
        $defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class);
        $defaultQuerySettings->setRespectStoragePage(false);
        $this->setDefaultQuerySettings($defaultQuerySettings);
    }

so that the storage pid is ignored ... It's still not working, findAll doesn't return an array of entites as it should

5条回答
迷人小祖宗
2楼-- · 2019-03-01 07:34

I would inspect the generated query itself. Configure the following option in the install tool:

$GLOBALS["TYPO3_CONF_VARS"]["sqlDebug"]

Note: dont do this in production environemnt!!

Explanation for sqlDebug:

Setting it to "0" will avoid any information being print on screen.

Setting it to "1" will show errors only.

Setting it to "2" will print all queries on screen.

So in Production you want to keep it at "0", in development environments you should set it to "1", if you want to know why some result is empty, configure it to "2".

I would guess that some enablefield configuration causes your problem.

If you retrieve an object by findByUid you will have the return because enablefields are ignored. In every other case enablefields are applied and that may cause your empty result.

查看更多
▲ chillily
3楼-- · 2019-03-01 07:38

Use additionally typoscript module configuration, like

module.tx_hwforms.persistence.storagePid = 112

Ensure your Typoscript is loaded in root. For BE modules I prefere to use

EXT:hwforms/ext_typoscript_setup.txt

where you write your module and extbase configuration.

查看更多
做个烂人
4楼-- · 2019-03-01 07:44

Repository must return a QueryResult from the findAll methods. Only methods which return a single object (findOneByXYZ) will return anything else.

All of the following operations will cause a QueryResult to load the actual results it contains. Until you perform one of these, no results are loaded and debugging the QueryResult will yield no information except for the original Query.

  • $queryResult->toArray();
  • $queryResult->offsetGet($offset); and $queryResult[$offset];
  • $queryResult->offsetExists($offset);
  • $queryResult->offsetSet($offset, $value); and $queryResult[$offset] = $value; (but be aware that doing this yourself with a QueryResult is illogical).
  • $queryResult->offsetUnset($offset); and unset($queryResult[$offset]); (again, illogical to use this yourself)
  • $queryResult->current(), ->key(), ->next(), ->prev(), ->rewind() and ->valid() which can all be called directly or will be called if you begin iterating the QueryResult.

Note that ->getFirst() and ->count() do not cause the original query to fire and will not fill results if they are not already filled. Instead, they will perform an optimised query.

Summa summarum: when you get a QueryResult you must trigger it somehow, which normally happens when you begin to render the result set. It is not a prefilled array; it is a dynamically filled Iterator.

查看更多
乱世女痞
5楼-- · 2019-03-01 07:45

Try to debbug like below and check findAll() method present for this repositry. I think this is useful for you click here

\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(get_class_methods($this->yourRepositryName)); exit();

Afetr added all your changes once you need to uninsatll/install extension.

查看更多
够拽才男人
6楼-- · 2019-03-01 07:51

This should work.there must be issue with your storage page in FindAll() extbase check for storage but in findByXXX() it ignore storage.

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\Extbase\\Object\\ObjectManager');
$querySettings = $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);

$this->cityRepository->setDefaultQuerySettings($querySettings);
$cities = $this->cityRepository->findAll();
查看更多
登录 后发表回答