我正在用ACL使用Sonata-Admin包,但是我必须以编程的方式创建一些对象。但我不知道如何正确地更新所创建实体的ACL表。所以我总是要执行
php应用/控制台奏鸣曲:admin:
当然,这不是一个永久的解决办法。
我尝试这样做:http://symfony.com/doc/current/cookbook/security/acl.html#creating-an-acl-and-adding-an-ace,所以我在实体中实现了DomainObjectInterface,并添加了getObjectIdentifier方法。
但是现在我在执行时得到了一个Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException异常:
php应用/控制台奏鸣曲:admin:
所以我想当使用奏鸣曲管理时,这不是正确的方法。但我在文件里什么都找不到。
发布于 2015-06-08 13:51:56
好的,我花了一些时间来调试,我想我找到了一个很好的解决方案:
获取要创建的对象的管理类:
$whateverAdmin = $this->get('app.admin.whatever');
//create the object
$whatever = new Whatever();
$whatever->setName('test');现在使用admin类创建对象:
$whateverAdmin->create($whatever);或者,如果您想使用entityManager来持久化,您只需使用admin类更新ACL:
$em->persist($whatever);
$em->flush(); // important to flush first so an ID ist generated
$whateverAdmin->createObjectSecurity($whatever);https://stackoverflow.com/questions/30488874
复制相似问题