1

在自定义 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:

4

2 回答 2

5

回答问题;

<f:debug>{institutions}</f:debug>

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

于 2019-05-07T12:34:31.693 回答
1

在我的情况下,以下方法与我的<f:debug>工作相同并且工作相似:

     \TYPO3\CMS\Core\Utility\DebugUtility::debug(
        $var = $variable,
        $header = 'Institutions',
        $group = ''
     );

     \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
        $variable,
        $title = 'Institutions', 
        $maxDepth = 8,
        $plainText = FALSE,
        $ansiColors = TRUE,
        $return = FALSE,
        $blacklistedClassNames = NULL,
        $blacklistedPropertyNames = NULL
     );

在列表中执行或在控制器中显示操作。

它不如 f:debug 方便(因为您必须在两个不同的地方完成工作,例如,当您在模板中的循环中时,您必须转到控制器并再次构建该循环),但它是有用的解决方法。

编辑:我发现这样做就足够了

<f:debug>{var}</f:debug>

在一条线上

于 2018-04-01T21:19:50.900 回答