5

我将它SonataAdminBundle用作 Symfony2 (v2.0.x) 支持的网站的管理界面的基础。

在 SonataAdmin 中添加到仪表板的实体默认具有以下操作:

  • 添加
  • 列表

这适用于大多数实体,但是该网站有一些实体没有通过管理界面添加数据 - 即它们是从面向公众的网站输入的。管理员只需查看它们(仪表板中的“列表”操作)、编辑或删除它们。管理员应该不能向这些实体添加数据。

有没有办法配置在 SonataAdmin 仪表板中的各个实体旁边显示哪些操作?

4

2 回答 2

11

在您的EntityAdmin班级中添加以下内容

public function configureRoutes(RouteCollection $collection)
{
  $collection->remove('create');
}
于 2012-03-07T13:31:12.693 回答
9

要从您的Admin班级中删除一条路线,请使用

protected function configureRoutes(RouteCollection $collection)
    {
        $collection->remove('edit');
    }

Symfony 2.1+中,您可以使用clearExcept删除所有路由,除了给定的路由,如下所示:

public function configureRoutes(RouteCollection $collection)
{
  $collection->clearExcept(array('list', 'edit', 'delete', 'batch'))
}

这样做的好处是可以在添加新操作的情况下保持您的操作不变SonataAdminBundle

Symfony 2.0中,也有一个类似的未记录函数(感谢 Jeroen):

public function configureRoutes(RouteCollection $collection)
{
  $collection->removeAllExcept(array('list', 'edit', 'delete', 'batch'))
}
于 2012-08-21T19:55:36.073 回答