[英]Sonata Admin Dashboard: configure actions per entity
I'm using the SonataAdminBundle
as base for an administration interface for a Symfony2 (v2.0.x) powered website. 我使用SonataAdminBundle
作为Symfony2(v2.0.x)驱动的网站的管理界面的基础。
Entities which are added to the dashboard in SonataAdmin have the following actions by default: 在SonataAdmin中添加到仪表板的实体默认情况下具有以下操作:
This works fine for most entities, however the website has a few entities for which data is not added via the admin interface - ie they are entered from the public facing website. 这适用于大多数实体,但是该网站有一些实体,其数据不是通过管理界面添加的 - 即它们是从面向公众的网站输入的。 Administrators only need to view them ("list" action in dashboard), edit them or delete them. 管理员只需要查看它们(仪表板中的“列表”操作),编辑它们或删除它们。 Administrators should not be able to add data to these entities. 管理员不应该能够向这些实体添加数据。
Is there a way to configure which actions are displayed next to individual entities in SonataAdmin dashboard? 有没有办法配置SonataAdmin仪表板中各个实体旁边显示哪些操作?
In your EntityAdmin
class add following 在您的EntityAdmin
类中添加以下内容
public function configureRoutes(RouteCollection $collection)
{
$collection->remove('create');
}
To remove a single route from your Admin
class, use 要从Admin
类中删除单个路由,请使用
protected function configureRoutes(RouteCollection $collection)
{
$collection->remove('edit');
}
In Symfony 2.1+ , you might use clearExcept
to remove all routes except the ones given, like this: 在Symfony 2.1+中 ,您可以使用clearExcept
删除除给定路由之外的所有路由,如下所示:
public function configureRoutes(RouteCollection $collection)
{
$collection->clearExcept(array('list', 'edit', 'delete', 'batch'))
}
This has the advantage of keeping your actions as they are in case of new actions being added to SonataAdminBundle
. 这样做的好处是可以保持您的操作,以防将新操作添加到SonataAdminBundle
。
In Symfony 2.0 , there is a similar undocumented function as well (thanks Jeroen): 在Symfony 2.0中 ,还有类似的未记录功能(感谢Jeroen):
public function configureRoutes(RouteCollection $collection)
{
$collection->removeAllExcept(array('list', 'edit', 'delete', 'batch'))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.