我使用的是Symfony 4.4和奏鸣曲-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 ]但是在浏览器中加载奏鸣曲页面时不会加载它。我还应该做点什么吗?
发布于 2022-03-25 13:33:54
你怎么知道没装子弹?在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注册,因为服务自动布线。
https://stackoverflow.com/questions/71613992
复制相似问题