TYPO3: repository->findAll() not working

雨燕双飞 提交于 2019-12-02 02:07:38

问题


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


回答1:


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.




回答2:


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



回答3:


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:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/44539156/typo3-repository-findall-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!