首页 > 解决方案 > 在自己的viewhelper中使用外国模型作为参数

问题描述

从流体中,我称我的 viewhelper 类 <ext:thehelper adr="{adr}" /> {adr} 是 tt_address → FriendsOfTYPO3\TtAddress\Domain\Model\Address 的数组

在viewhelper中我注册了参数

    use FriendsOfTYPO3\TtAddress\Domain\Model\Address;
    public function initializeArguments() {
        $this->registerArgument('adr', 'FriendsOfTYPO3\TtAddress\Domain\Model\Address', 'the addresses', true);
    }

失败并显示此消息:参数“adr”已注册为“FriendsOfTYPO3\TtAddress\Domain\Model\Address”类型,但在视图助手中属于“TYPO3\CMS\Extbase\Persistence\Generic\QueryResult”类型

如何接收要使用的 adr-array。谢谢您的帮助!

标签: typo3view-helpers

解决方案


如果您的 VH 必须接受多个地址,那么您的 ViewHelper 参数不得将查询结果中包含的任何对象的类名注册为数据类型。

相反,您必须使用 type 注册参数TYPO3\CMS\Extbase\Persistence\Generic\QueryResult


推荐阅读