[英]custom action in SonataAdminBundle
On this page I found how to add route for my custom action. 在这个页面上,我找到了如何为自定义操作添加路由。
protected function configureRoutes(RouteCollection $collection) {
$collection->add('ispremium', $this->getRouterIdParameter().'/ispremium');
}
After that I add custom action in my Admin class: 之后,我在Admin类中添加自定义操作:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('code', null, array('label' => 'Code'))
->add('_action', 'actions', array(
'actions' => array(
'ispremium' => array(
'template' => 'AppMyBundleBundle:Admin:ispremium.html.twig'
)
)
))
;
}
It generated url like this: 它生成的URL如下:
/app_dev.php/admin/mobispot/discodes/discode/300876/ispremium
My template for this link: 我的链接模板:
<a href="{{ admin.generateObjectUrl('ispremium', object) }}">Link</a>
I dont' know how to solve this problems: 我不知道如何解决这个问题:
How to define custom controller for that route pass? 如何为该路由传递定义自定义控制器? Now I have an error: 现在我有一个错误:
Method "Sonata\\AdminBundle\\Controller\\CRUDController::ispremiumAction" does not exist. 方法“Sonata \\ AdminBundle \\ Controller \\ CRUDController :: ispremiumAction”不存在。
Can I change generated url with generateUrl method? 我可以使用generateUrl方法更改生成的网址吗?
When you are creating service for EntityAdmin
class the third argument is the controller name. 在为EntityAdmin
类创建服务时,第三个参数是控制器名称。 You can create a class that extends CRUDController
and set it in service. 您可以创建一个扩展CRUDController
并将其设置为服务的类。 eg 例如
The controller, 控制器,
//Vendor\YourBundle\Controller\EntityAdminController.php
class EntityAdminController extends CRUDController
{
public function ispremiumAction()
{
//process
}
}
In services.yml
, 在services.yml
,
entity.admin.service:
class: FQCN\Of\EntityAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: your_group, label: Label }
arguments: [null, FQCN\Of\Entity, VendorYourBundle:EntityAdmin]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.