我在Admin类中添加了以下代码,
class ProductPriceAdmin extends Admin
{
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->add('price'); //I want to add a "id" as route parameter
}
}
这里价格是我在控制器中声明的自定义函数,如下所示,
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'),
));
}
}
添加动态路由时如何添加路由参数?
谢谢, 费萨尔纳西尔
答案 0 :(得分:2)
试试这个:
$collection->add('edit_price', 'price/{id}');
你也可以在Symfony \ Component \ Routing \ Route \ RouteCollection方法中查看add()。