How to implement SonataAdmin forms and lists into own controllers with different logic and templates?
1 に答える
I sugest you have a look at Sonata\AdminBundle\Controller\CRUDController, there you have everything you need:
Say you have an admin for 'User' entities and the service name for this admin is 'myapp.admin.user' (in services.xml or alike)
In your controller you can get the admin class with:
$user_admin = $this->container->get('sonata.admin.pool')
->getAdminByAdminCode('myapp.admin.user');
you can get the admin form with:
$form = $user_admin->getForm();
and if you look at the listAction() method in that class you can see how to get the datagrid for building the lists:
$datagrid = $user_admin->getDatagrid();
For the templates you can extend or adapt the templates at Sonta/AdminBundle/Resources/views/CRUD for the list and edit actions.