I want to override the tird-party bundle's controller
in Symfony4.
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
It doesn't work,, maybe of course though.
However, what should I do next???
Thanks to @DreamOn comment
I made the file 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.
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.
It makes me confused.
How can I register/routing my Controller?
I use this instead, not override.
Extend bundle controller. Add bundle controller as a base controller by:
use Sonata\\AdminBundle\\Controller\\CRUDController as BaseCRUDController;
And make your CRUDController extends BaseCRUDController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.