高级配置

编辑本页

请注意

%管理器类型%将被管理器类型(orm, doctrine_mongodb…)取代,默认的route_builder依赖于它。

在服务配置文件中定义依赖项有两种方法(services . xmlservices.yaml):

如果你想要修改将要被注入的服务,将以下代码添加到应用程序的配置文件中:

  • YAML
1 2 3 4 5 6 7
#配置/包/ sonata_admin.yaml管理员:sonata_admin:sonata.order.admin.order:此设置的管理服务的# idmodel_manager:#依赖项名称,从上表sonata.order.admin.order.manager#自定义服务id
  • YAML
  • XML
1 2 3 4 5 6 7
#配置/ services.yaml服务:app.admin.entity_route_builder:类:应用\ \ EntityRouterBuilder路线参数:-“@sonata.admin.audit.manager”

12 3 4 5 6 7 8 9 10 11 12 13
公共函数configureActionButtons(AdminInterface管理数组,列表、字符串行动,对象对象= null):数组如果(in_array (行动, (“显示”“编辑”“acl”) & &对象) {buttonList“自定义”] = [“模板”= >“@App /按钮/ custom_button.html.twig ',);}//删除历史操作设置buttonList“历史”]);返回buttonList;}

您的自定义树枝文件

1 2 3 4 5 6 7 8
{# @App /按钮/ custom_button.html。树枝#}<><一个href{{管理。generateObjectUrl('custom', object)}}><“fa fa-cogs”aria-hidden“真正的”>>自定义一个>>
自定义操作按钮"></figure>
            </div>
            <div class=

超文本标记语言,身体而且侧边栏元素延伸。默认情况下,这些容器被强制为全高度。如果使用自定义布局或不需要此类行为,请添加没有拉伸类的< html >标签。

1 2 3
{/ standard_layout.html #模板。树枝#}{%html_attributes %}类= " no-js没有拉伸”{%endblock%}

12 3 4 5 6 7 8 9 10 11 12
/ / src / Admin / CustomAdmin.php最后CustomAdmin扩展AbstractAdmin受保护的函数getAccessMapping():数组返回“myCustomFoo”= >“编辑”“myCustomBar”= > [“编辑”“列表”]];}}

12 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20
/ / src /控制器/ CustomCRUDController.php最后CustomCRUDController扩展CRUDController公共函数myCustomFooAction():响应->管理->checkAccess (“myCustomFoo”);//如果您无法访问链接管理员的EDIT角色,将抛出AccessDeniedException异常/ /……公共函数myCustomBarAction对象:响应->管理->checkAccess (“myCustomBar”对象);//如果无法访问链接管理员的EDIT AND LIST角色,将抛出AccessDeniedException异常/ /……}}

您还可以通过为特定的Admin类创建自定义SecurityHandler服务来完全自定义您想要处理的访问管理:

12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/ / src /安全/处理/ CustomSecurityHandler.php使用奏鸣曲AdminBundle安全处理程序SecurityHandlerInterface最后CustomSecurityHandler扩展SecurityHandlerInterface公共函数isGranted(AdminInterface管理属性,对象对象= null):保龄球返回->customAccessLogic ();}公共函数getBaseRole(AdminInterface管理:字符串返回;}公共函数buildSecurityInformation(AdminInterface管理:数组返回[];}公共函数createObjectSecurity(AdminInterface管理、对象对象:无效{}公共函数deleteObjectSecurity(AdminInterface管理、对象对象:无效{}}

使用' security_handler '标签指向特定管理类的自定义SecurityHandler服务:

1 2 3 4 5 6 7 8
#配置/ services.yaml服务:#……admin.custom:类:App \ Admin \ CustomAdmin标签:-名称:sonata.admin,model_class:应用\ \实体定义,manager_type:orm,标签:类别,security_handler:App \ CustomSecurityHandler \安全\处理程序

你也可以在你的自定义SecurityHandler中使用默认的SecurityHandler(在全局配置中定义):

12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/ / src /安全/处理/ CustomSecurityHandler.php使用奏鸣曲AdminBundle安全处理程序SecurityHandlerInterface最后CustomSecurityHandler扩展SecurityHandlerInterface私人SecurityHandlerInterfacedefaultSecurityHandler公共函数__construct(SecurityHandlerInterfacedefaultSecurityHandler->defaultSecurityHandler =defaultSecurityHandler;}公共函数isGranted(AdminInterface管理属性,对象对象= null):保龄球//自定义访问逻辑如果(…){返回;}//默认访问逻辑返回->defaultSecurityHandler->isGranted (管理属性对象);}/ /……
1 2 3 4 5 6 7
#配置/ services.yaml服务:#……App \安全\处理器\ CustomSecurityHandler:参数:-“@sonata.admin.security.handler”

如果你有很多使用默认SecurityHandler服务的SecurityHandler服务,你可以定义一个服务别名:

1 2 3 4 5
#配置/ services.yaml服务:#……奏鸣曲\ AdminBundle \安全\处理器\ SecurityHandlerInterface:“@sonata.admin.security.handler”

这样,您就不需要定义每个自定义的SecurityHandler服务来指定默认的SecurityHandler服务作为参数。

CRUDController未指定控制器时使用的控制器。您可以通过在配置中添加以下内容来修改此配置:

  • YAML
1 2 3 4
#配置/包/ sonata_admin.yamlsonata_admin:default_controller:应用程序控制器\ \ DefaultCRUDController

此工作,包括代码示例,是根据<一个rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">创作共用BY-SA 3.0许可证。
确保你的项目没有风险"></一个><p class=确保你的项目没有风险

在几分钟内完成从开发到登台、制作再返回的过程"></一个><p class=在几分钟内完成从开发到登台、制作再返回的过程

代码消耗服务器资源。黑火告诉你怎么做"></一个><p class=代码消耗服务器资源。黑火告诉你怎么做