You should hint the parameter if the file is in other namespace, and the add() method should work, but then you have to overwrite the Sonata's CRUD template to be able to display an other button/link.
Additionally you can define the controller and action which will be called.
For example:
src/Acme/DemoBundle/Admin/EntityAdmin.php:
protected function configureRoutes(SonataAdminBundleRouteRouteCollection $collection)
{
$collection
->add('dummy',
'dummy/{id}',
array('_controller' => 'AcmeDemoBundle:Default:dummy'),
array('id' => 'd+')
)
;
}
src/Acme/HelloBundle/Controller/DefaultController.php:
/**
@Route("/dummy/{id}", name="dummy",
requirements={"id" = "d+"}
)
@Template("AcmeDemoBundle:Default:dummy.html.twig")
*/
public function dummyAction($id)
{
return(array(
'id' => $id
));
}
app/Resources/SonataAdminBundle/views/CRUD/base_edit_form.html.twig:
{% block form %}
...
{% else %}
...
{% block formactions %}
...
{% else %}
...
{% if admin.id(object) %}
...
{% if admin.hasroute('dummy') %}
<a class="btn" target="_blank" href="{{ admin.generateObjectUrl('dummy', object) }}">{% trans from 'SonataAdminBundle' %}link_dummy{% endtrans %}</a>
{% endif %}
...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…