[英]sonata-admin: creating a voter
我正在使用 Symfony 4.4 和 sonata-admin 3.107
我為我的一個管理頁面 (SampleAdmin) 創建了一個投票器。
class SampleVoter extends Voter
{
protected function supports($attribute, $subject): bool
{
return in_array($attribute, ['LIST', 'VIEW', 'CREATE', 'EDIT'])
&& $subject instanceof 'App\Entity\Sample';
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if ($attribute === 'EDIT') {
return false;
}
return true;
}
}
我在我的服務中注冊了它:
App\Voter\SampleVoter:
tags: [ security.voter ]
但是在瀏覽器中加載奏鳴曲頁面時並沒有加載。 我應該做更多的事情嗎?
你怎么知道沒有加載? 在supports()
方法中引發異常:
class SampleVoter extends Voter
{
protected function supports($attribute, $subject): bool
{
return in_array($attribute, ['LIST', 'VIEW', 'CREATE', 'EDIT']);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if ($attribute === 'EDIT') {
return false;
}
return true;
}
}
順便說一句,不需要在 services.yaml 中注冊,因為服務自動連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.