I have added the following code in my Admin class,
class ProductPriceAdmin extends Admin
{
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->add('price'); //I want to add a "id" as route parameter
}
}
Here price is my custom function which I have declared in the controller as below,
class ProductPriceController extends Controller
{
public function priceAction($id) //I want to use this variable
{
if (false === $this->admin->isGranted('LIST')) {
throw new AccessDeniedException();
}
$datagrid = $this->admin->getDatagrid();
$formView = $datagrid->getForm()->createView();
// set the theme for the current Admin Form
$this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
return $this->render($this->admin->getTemplate('list'), array(
'action' => 'list',
'form' => $formView,
'datagrid' => $datagrid,
'csrf_token' => $this->getCsrfToken('sonata.batch'),
));
}
}
How to add route parameter when adding dynamic routing ?
Thanks, Faisal Nasir
Try this:
$collection->add('edit_price', 'price/{id}');
also you can view in Symfony\Component\Routing\Route\RouteCollection method add().