如何在TYPO3中调试 返回字符串而不是对象?

问题描述 投票:0回答:2

在自定义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:forf:debug遍历{institutions}:

<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:

typo3 fluid extbase typo3-8.7.x
2个回答
2
投票

回答这个问题;

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

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


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>

在一条线上

© www.soinside.com 2019 - 2024. All rights reserved.