如果 <f:debug> 返回字符串而不是对象,如何在 TYPO3 中进行调试?

Urs*_*Urs 1 typo3 fluid extbase typo3-8.7.x

在自定义 TYPO3 8.7.12 extbase 扩展中,我无法访问f:debug模板中的项目。

\n\n

我们在 listAction 控制器中,只需执行以下操作:

\n\n
    $institutions = $this->institutionRepository->findAll();\n    $this->view->assignMultiple([\n        \'institutions\' => $institutions,\n        // ... pagination limit ...\n        ]\n    );\n
Run Code Online (Sandbox Code Playgroud)\n\n

并在模板中:

\n\n
 <f:debug>\n    {institutions}                            \n </f:debug>\n
Run Code Online (Sandbox Code Playgroud)\n\n

这返回

\n\n
    \n
  • 有时流体调试器中的字符串“Array”(现在无法重现)
  • \n
  • 当代码有3行时:#1273753083: Cannot cast object of type "TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult" to string.
  • \n
  • 或者也#1273753083: Cannot cast object of type "TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage" to string.
  • \n
  • 当代码在 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.
  • \n
\n\n

f:for如果我用and then循环遍历 {institutions} f:debug

\n\n
<f:for each="{institutions}" as="institution" iteration="i">\n    <f:debug>\n      {institution}\n    </f:debug>\n</f:for>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我得到了对象的第一个属性,例如名称。

\n\n

编辑:这是由于__toString()模型中的魔术方法造成的。如果我删除它,我会得到命名空间和 uid STUBR\\Extension\\Domain\\Model\\Institution:55\xe2\x80\x93 ,这看起来又好像对象没有渲染一样。

\n\n

等等... 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\n

附:

\n\n\n

小智 5

回答问题;

<f:debug>{institutions}</f:debug>
Run Code Online (Sandbox Code Playgroud)

将被解析为对象,但内部的任何空格都会使其解析为字符串。