[英]Sonata User Bundle custom batch action
so as the title suggests, I need to add custom batch action to SonataUserBundle
. 因此,正如标题所示,我需要向
SonataUserBundle
添加自定义批处理操作。
With this action, the operator can send a message to all of the users (or selected ones). 通过此操作,操作员可以向所有用户(或选定的用户)发送消息。 Therefore it needs to extend
SonataAdminBundle
in order to be able to add a custom view for this action. 因此,它需要扩展
SonataAdminBundle
以便能够为此操作添加自定义视图。
The problem is, ApplicationSonataUserBundle.php
is overriding SonataUserBundle
: 问题是,
ApplicationSonataUserBundle.php
覆盖了SonataUserBundle
:
class ApplicationSonataUserBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'SonataUserBundle';
}
}
and if I change it, it will break the Bundle. 如果我更改它,它将破坏捆绑软件。
Is there any solutions that I can add this batch action to the bundle? 有什么解决方案可以将此批处理操作添加到捆绑软件中?
What you need is editing the sonata_user config to use you own Controller instead of the default Sonata Admin CRUD Controller. 您需要编辑sonata_user配置以使用您自己的控制器,而不是默认的Sonata Admin CRUD控制器。
So in your config.yml add the following: 因此,在您的config.yml中添加以下内容:
sonata_user:
admin:
user:
controller: MyAppMyBundle:UserAdmin
And create your own controller that extend CRUDController 并创建自己的控制器来扩展CRUDController
namespace MyApp\MyBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
class UserAdminController extends Controller
{
}
now you can add your own batch actions like this 现在您可以添加自己的批处理操作,例如
class UserAdminController extends Controller
{
public function batchActionSendMail(ProxyQueryInterface $selectedModelQuery)
{
$selectedModels = $selectedModelQuery->execute();
// Your stuff here
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}
}
Hope it will help someone :) 希望它可以帮助某人:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.