I have a project with symfony 2
and im using a SonataAdminBundle
for my backend. How can i override a dashboardAction()
to extend them for more features ?
The routing configuration for this sonata admin 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>
Let say you have a bundle named 'My/AdminBundle' that holds the controller that should extend the 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 /My/AdminBundle/Resources/config/routing.yml (you might have different configuration format such as xml)
sonata_admin_dashboard: pattern: /dashboard defaults: { _controller: MyAdminBundle:Core:dashboard }
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 just so you know I have not used this in a project. I just check it locally and it worked. It is possible that this is not the best solution!
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With