首页 文章

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

提问于
浏览
0

在自定义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 然后 f:debug 遍历

<f:for each="{institutions}" as="institution" iteration="i">
    <f:debug>
      {institution}
    </f:debug>
</f:for>

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

EDIT: 这是由于模型中的 __toString() 魔术方法 . 如果我删除它,而是我得到命名空间和uid STUBR\Extension\Domain\Model\Institution:55 - 这再次看起来好像没有渲染对象 .

Wait... php.net说 The __toString() method allows a class to decide how it will react when it is treated like a string . 那么可以将对象作为字符串处理(类型转换?)?

使用属性是正常的,只有在尝试打印整个对象时才会出现问题 .

我应该在哪里看?懒加载?有一些延迟加载属性,但不是很多 . 或者班上可能缺少某些东西?或者有解决方法吗?

PS:

1 回答

  • 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更不方便(因为你必须在两个不同的地方做工作,例如当你在模板中的循环中,你必须去控制器并再次构建该循环),但它是一个有用的解决方法 .

相关问题