Replace ligament action

I have a project with symfony 2 and im using SonataAdminBundle for my backend. How can I override dashboardAction() to extend them for more functions?

+4
source share
1 answer

The routing configuration for this sonata administrator can be found in

 // vendor/bundles/Sonata/AdminBundle/Resources/config/routing/sonata_admin.xml <route id="sonata_admin_dashboard" pattern="/dashboard"> <default key="_controller">SonataAdminBundle:Core:dashboard</default> </route> 

Say you have a package called "My / AdminBundle" that contains a controller that should extend dashboardActions. Then try the following:

  • Create a controller in /My/AdminBundle/Controller/CoreController.php

     namespace My\AdminBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; use Sonata\AdminBundle\Controller\CoreController as BaseCoreContBroller; class CoreController extends BaseCoreContBroller { public function dashboardAction() { // your custom code // call parent method parent::dashboardAction(); } } 
  • Open the bundle routing configuration file located at /My/AdminBundle/Resources/config/routing.yml (you may have a different configuration format such as xml)

  sonata_admin_dashboard:
      pattern: / dashboard
      defaults: {_controller: MyAdminBundle: Core: dashboard}
  • Open the application routing configuration file and add the following after setting up the sonata so that it cancels it.
  admin:
     resource: '@ SonataAdminBundle / Resources / config / routing / sonata_admin.xml'
     prefix: / admin

 _sonata_admin:
     resource:.
     type: sonata_admin
     prefix: / admin

 MyAdminBundle:
     resource: "@ MyAdminBundle / Resources / config / routing.yml"
     prefix: / admin

Disclaimer so that you know that I have not used this in a project. I just check it locally and it worked. This may not be the best solution!

Hope this helps

+7
source

Source: https://habr.com/ru/post/1389355/


All Articles