[英]How to override the controller for Symfony4
I want to override the tird-party bundle's controller
in Symfony4.我想在 Symfony4 中覆盖第三方包的controller
。
in this explanation .在这个解释中。
It says.它说。
If the controller is a service, see the next section on how to override it.如果控制器是一项服务,请参阅下一节了解如何覆盖它。 Otherwise, define a new route + controller with the same path associated to the controller you want to override (and make sure that the new route is loaded before the bundle one).否则,使用与要覆盖的控制器关联的相同路径定义一个新的路由 + 控制器(并确保在捆绑包之前加载新路由)。
What I want to do is to override this Controller.我想要做的是覆盖这个控制器。
myapp/vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php
Now I make CRUDController.php in myapp/src/Controller/CRUDController.php
现在我在myapp/src/Controller/CRUDController.php
It doesn't work,, maybe of course though.它不起作用,也许当然。
However, what should I do next???然而,接下来我该怎么办???
Thanks to @DreamOn comment感谢@DreamOn 评论
I made the file myapp/src/Controller/CRUDController.php我制作了文件 myapp/src/Controller/CRUDController.php
<?php
namespace App\Controller;
use Sonata\AdminBundle\Controller\CRUDController as BaseCRUDController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class CRUDController extends BaseCRUDController{
}
But, it doesn't work, I guess I should do some routing setting.但是,它不起作用,我想我应该做一些路由设置。
Normally SonataAdmonBundle
is routed like this.通常SonataAdmonBundle
是这样路由的。
routing.yml
admin_area:
resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
However Symfony4/3.4 recommend annotation routing.然而 Symfony4/3.4 推荐注解路由。
It makes me confused.这让我很困惑。
How can I register/routing my Controller?如何注册/路由我的控制器?
Extend bundle controller.扩展捆绑控制器。 Add bundle controller as a base controller by:通过以下方式将捆绑控制器添加为基本控制器:
use Sonata\\AdminBundle\\Controller\\CRUDController as BaseCRUDController;使用 Sonata\\AdminBundle\\Controller\\CRUDController 作为 BaseCRUDController;
And make your CRUDController extends BaseCRUDController并使您的 CRUDController 扩展 BaseCRUDController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.