Urs*_*Urs 1 typo3 fluid extbase typo3-8.7.x
在自定义 TYPO3 8.7.12 extbase 扩展中,我无法访问f:debug模板中的项目。
我们在 listAction 控制器中,只需执行以下操作:
\n\n $institutions = $this->institutionRepository->findAll();\n $this->view->assignMultiple([\n \'institutions\' => $institutions,\n // ... pagination limit ...\n ]\n );\nRun Code Online (Sandbox Code Playgroud)\n\n并在模板中:
\n\n <f:debug>\n {institutions} \n </f:debug>\nRun Code Online (Sandbox Code Playgroud)\n\n这返回
\n\n#1273753083: Cannot cast object of type "TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult" to string.#1273753083: Cannot cast object of type "TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage" to string.#1234386924: Cannot create empty instance of the class "TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage" because it does not implement the TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface. f:for如果我用and then循环遍历 {institutions} f:debug:
<f:for each="{institutions}" as="institution" iteration="i">\n <f:debug>\n {institution}\n </f:debug>\n</f:for>\nRun Code Online (Sandbox Code Playgroud)\n\n我得到了对象的第一个属性,例如名称。
\n\n编辑:这是由于__toString()模型中的魔术方法造成的。如果我删除它,我会得到命名空间和 uid STUBR\\Extension\\Domain\\Model\\Institution:55\xe2\x80\x93 ,这看起来又好像对象没有渲染一样。
等等... php.net 说The __toString() method allows a class to decide how it will react when it is treated like a string。那么是否可以将对象视为字符串(类型转换?)?
使用属性是正常的,问题只是在尝试打印整个对象时发生。
\n\n我应该去哪里看?延迟加载?有一些延迟加载属性,但不是很多。或者也许课堂上缺少一些东西?或者有没有解决方法。
\n\n附:
\n\ninitStorageObjects()已经在构造函数中调用小智 5
回答问题;
<f:debug>{institutions}</f:debug>
Run Code Online (Sandbox Code Playgroud)
将被解析为对象,但内部的任何空格都会使其解析为字符串。
| 归档时间: |
|
| 查看次数: |
2565 次 |
| 最近记录: |