在自定义 TYPO3 8.7.12 extbase 扩展中,我无法f:debug
在模板中添加项目。
我们在 listAction 控制器中,只需执行以下操作:
$institutions = $this->institutionRepository->findAll();
$this->view->assignMultiple([
'institutions' => $institutions,
// ... pagination limit ...
]
);
在模板中:
<f:debug>
{institutions}
</f:debug>
这返回
- 有时流体调试器中的字符串“Array”(现在无法重现)
- 当代码在 3 行时:
#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.
- 当代码在 1 行时:
#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遍历 {institutions} f:debug
:
<f:for each="{institutions}" as="institution" iteration="i">
<f:debug>
{institution}
</f:debug>
</f:for>
我得到对象的第一个属性,例如名称。
编辑:这是由于__toString()
模型中的一种魔术方法。如果我删除它,我会得到命名空间和 uid——STUBR\Extension\Domain\Model\Institution:55
这看起来好像对象没有被渲染。
等等... php.net 说The __toString() method allows a class to decide how it will react when it is treated like a string
。那么是否可以将对象视为字符串(类型转换?)?
使用属性是正常的,仅在尝试打印整个对象时才会出现问题。
我应该去哪里看?延迟加载?有一些延迟加载属性,但不是很多。或者,也许课堂上缺少了什么?或者有没有解决办法。
PS:
- 无法 print_r 或 var_dump 查询结果,我收到内存限制错误。
- 我看到了https://wiki.typo3.org/Exception/CMS/1234386924但
initStorageObjects()
已经在构造函数中调用