On this page I found how to add route for my custom action.
protected function configureRoutes(RouteCollection $collection) {
$collection->add('ispremium', $this->getRouterIdParameter().'/ispremium');
}
After that I add custom action in my Admin class:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('code', null, array('label' => 'Code'))
->add('_action', 'actions', array(
'actions' => array(
'ispremium' => array(
'template' => 'AppMyBundleBundle:Admin:ispremium.html.twig'
)
)
))
;
}
It generated url like this:
/app_dev.php/admin/mobispot/discodes/discode/300876/ispremium
My template for this link:
<a href="{{ admin.generateObjectUrl('ispremium', object) }}">Link</a>
I dont' know how to solve this problems:
How to define custom controller for that route pass? Now I have an error:
Method "Sonata\AdminBundle\Controller\CRUDController::ispremiumAction" does not exist.
Can I change generated url with generateUrl method?
When you are creating service for
EntityAdmin
class the third argument is the controller name. You can create a class that extendsCRUDController
and set it in service. e.gThe controller,
In
services.yml
,