如何在部分VHS的AllowViewHelper中设置前端用户组



我想在 AllowViewHelper 中设置 frontendUserGroup 参数,但我不知道该怎么做。

有时(即使我刷新缓存也是不确定的)会弹出此错误:

参数"前端用户组"已注册为类型 "TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup",但类型为 视图助手中的"字符串" "FluidTYPO3\Vhs\ViewHelpers\Security\AllowViewHelper"

简单地将用户组的引用作为参数传递是否正确,如下所示?

{namespace v=FluidTYPO3VhsViewHelpers}
...
<v:security.allow frontendUserGroup="3">
  <f:then>
    <span>Access granted</span>
  </f:then>
  <f:else>
    <span>Access denied</span>
  </f:else>
</v:security.allow>

该参数由视图助手注册,如下所示:

$this->registerArgument('frontendUserGroup', 'TYPO3CMSExtbaseDomainModelFrontendUserGroup', 'The FrontendUserGroup to allow/deny');

根据您的示例,您可能只使用 CMS Fluid 附带的 security.hasRole ViewHelper:

<f:security.ifHasRole role="3">
  <f:then>
    <span>Access granted</span>
  </f:then>
  <f:else>
    <span>Access denied</span>
  </f:else>
</f:security.ifHasRole>

与 EXT:vhs 中的 allow ViewHelper 相反,此 ViewHelper 接受用户组的 UID 作为参数。除了UID,您还可以传递用户组的标题,但据我所知,这可能是模棱两可的。

你应该将实际的前端用户组对象(TYPO3CMSExtbaseDomainModelFrontendUserGroup)传递给你的视图。Extbase 提供了存储库,您可以将其注入控制器:

/**
 * @var TYPO3CMSExtbaseDomainRepositoryFrontendUserGroupRepository
 * @inject
 */
protected $frontendUserGroupRepository;
public function myAction() {
        ....
        $this->view->assign('specialUserGroup', $this->frontendUserGroupRepository->findByUid(3));
}

现在将此对象传递给 viewHelper:

<v:security.allow frontendUserGroup="{specialUserGroup}">

最新更新