I am new in Symfony as well as sonata admin, I want to make a custom route with custom action in sonata admin.any one know how to make a custom route with custom action and how to call that custom route from twing file ?.
Asked
Active
Viewed 1,254 times
0
-
There is not a sonata-admin for symfony 1.4. – Mohamed Ben HEnda Nov 13 '17 at 11:53
-
1i am use symphony 3 in that i use sonata admin – Sandeep Gajera Nov 13 '17 at 11:56
-
but your tags are symfony1 and symfony 1.4! – Mohamed Ben HEnda Nov 13 '17 at 11:57
-
please suggest me is there any way to make a custom route and action in symphony3 – Sandeep Gajera Nov 13 '17 at 11:59
-
The framework is Symfony not Symphony ;) – Mohamed Ben HEnda Nov 13 '17 at 11:59
1 Answers
0
Example of route in your AdminBundle:
<route id="get_driver_location" path="/driver-location">
<default key="_controller">MyAdminBundle:Core:getlocation</default>
</route>
Then you must create a controller called CoreController in the controller directory of your bundle
namespace My\AdminBundle\Controller;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Controller\CoreController as BaseController;
class CoreController extends BaseController {
public function getlocationAction() {
//your logic here
......
return $this->render($this->getAdminPool()->getTemplate('driver'), array(
'base_template' => $this->getBaseTemplate());
}
}
Edit: Add Twig:
-Resources
-views
-Core
-driver.html.twig
in the file driver.html.twig you make a route
<div>
<a class="btn btn-default" href="{{ path('get_driver_location') }}" role="button">
{{ "example"|trans({}, "MyAdminBundle") }}
</a>
</div>

Mohamed Ben HEnda
- 2,686
- 1
- 30
- 44
-
-
It give me below error. Error: "The controller for URI \"\/admin\/department_details\/4614\" is not callable. Expected method \"retrieveDepartmentDetailsAction\......" – Sandeep Gajera Nov 13 '17 at 12:26
-
Please, when you have an error, edit you post that contains all necessary informations about the error. – Mohamed Ben HEnda Nov 13 '17 at 12:29
-
1 ) I add Below code in vendor\sonata-project\admin-bundle\Resources\config\routing\sonata_admin.xml file
AppBundle:CRUD:retrieveDepartmentDetailsAction -
I Set above code and It give me Error below: There is no `_sonata_admin` defined for the controller `AppBundle\\Controller\\CRUDController` and the current route `get_department_details`" – Sandeep Gajera Nov 13 '17 at 12:49
-
no, never change the code in the vendor. you should add a new file called sonata_admin.xml in your bundle which will be contain the new route – Mohamed Ben HEnda Nov 13 '17 at 12:49
-
ok let me change it but one question is in which folder i make a sonata_admin.xml file ? – Sandeep Gajera Nov 13 '17 at 12:57
-
I make a sonata_admin.xml file in below folder of my bunddle D:\xampp\htdocs\meopin_2\trunk\src\AppBundle\Resources\config\routing\ But it give me error Below An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "get_department_details" as such route does not exist."). – Sandeep Gajera Nov 13 '17 at 13:02
-
please help me something is missing or wrong from my side , please suggest me – Sandeep Gajera Nov 13 '17 at 13:08
-
thanks for help it is done few change in your code and it will be done – Sandeep Gajera Nov 14 '17 at 13:37
-
and I also Folow https://groups.google.com/forum/#!topic/sonata-devs/8GK0kpa2cik link – Sandeep Gajera Nov 14 '17 at 13:38