[英]Symfony 4.1, sonata Admin won't be overridden
I wanted to override editAction method of Sonata Admin. 我想重写Sonata Admin的editAction方法。 I created an admin class and extended it from Sonata\\AdminBundle\\Controller\\CRUDController then I wrote editAction with my personal edit but when I access the edit post page, the old Sonata editAction gets called and not my function! 我创建了一个管理类,并从Sonata \\ AdminBundle \\ Controller \\ CRUDController对其进行了扩展,然后用个人编辑编写了editAction,但是当我访问编辑页面时,旧的Sonata editAction被调用,而不是我的函数! here is my admin class: 这是我的管理员班:
<?php
namespace App\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use App\Manager\SiteManagerInterface;
use App\Manager\UserManagerInterface;
use App\Entity\Site;
use App\Entity\Profile;
use App\Entity\User;
use App\Entity\Payment;
use Symfony\Component\HttpFoundation\Response;
class UserAdminCRUDController extends Controller
{
/** @var SiteManagerInterface $siteManager */
private $siteManager;
public function editAction($id = null)
{
return new Response("test");
}
}
I believe that you forgot to register the action service. 我相信您忘了注册动作服务。 You can do it by: Either by using XML: 您可以通过以下方式实现:使用XML:
<!-- src/Resources/config/admin.xml -->
<service id="app.admin.car" class="App\Admin\CarAdmin">
<tag name="sonata.admin" manager_type="orm" group="Demo" label="Car" />
<argument />
<argument>App\Entity\Car</argument>
<argument>App\Controller\CRUDController</argument>
</service>
or in an yml 或以yml
# src/Resources/config/admin.yml
services:
app.admin.car:
class: App\Admin\CarAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: Demo, label: Car }
arguments:
- null
- App\Entity\Car
- App\Controller\CRUDController
public: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.