禁用特定条目的操作
Disable action for specific entries
在 Sonata Admin 中,在我的一个部分中,我想禁用 4 个特定 entries/lines 的删除操作。
我知道我可以使用 configureRoutes()
对整个列表执行此操作,但找不到特定条目的任何内容。
我尝试了以下但 getSubject()
总是空的。
protected function configureRoutes(RouteCollection $collection)
{
$product = $this->getSubject();
if ($product && $product->getIsBase())
{
$collection->clearExcept(array('list', 'edit'));
}
}
谢谢
您必须在您的管理员中覆盖 isGranted
方法 class:
public function isGranted($name, $object = null)
{
if (in_array($name, array('LIST', 'EDIT')) && $object && $object->getIsBase()) {
return false;
}
return parent::isGranted($name, $object);
}
在 Sonata Admin 中,在我的一个部分中,我想禁用 4 个特定 entries/lines 的删除操作。
我知道我可以使用 configureRoutes()
对整个列表执行此操作,但找不到特定条目的任何内容。
我尝试了以下但 getSubject()
总是空的。
protected function configureRoutes(RouteCollection $collection)
{
$product = $this->getSubject();
if ($product && $product->getIsBase())
{
$collection->clearExcept(array('list', 'edit'));
}
}
谢谢
您必须在您的管理员中覆盖 isGranted
方法 class:
public function isGranted($name, $object = null)
{
if (in_array($name, array('LIST', 'EDIT')) && $object && $object->getIsBase()) {
return false;
}
return parent::isGranted($name, $object);
}