2013-12-09 3 views
0

я добавил следующий код в моем классе администратораКак добавить параметр маршрута в SonataAdminBundle Symfony2

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'), 
     )); 

    } 
} 

Как добавить параметр маршрута при добавлении динамической маршрутизации?

Спасибо, Фейсал Насир

ответ

2

Попробуйте это:

$collection->add('edit_price', 'price/{id}'); 

также можно просмотреть в методе Symfony \ Component \ Routing \ Route \ RouteCollection добавить().

Смежные вопросы