2012-09-17 3 views
9

소나타 관리 번들에 액션을 추가하려고합니다. 나는 내 관리 클래스를 변경 :SonataAdminBundle에서 액션 추가하기

protected function configureListFields(ListMapper $listMapper) 
{ 
    $listMapper 
     ->addIdentifier('id') 
     ->add('name')   
     // add custom action links 
     ->add('_action', 'actions', array(
      'actions' => array(
       'view' => array(), 
       'calculate' => array('template' => 'myappMyBundle:Admin:list__action_calculate.html.twig'), 
       'edit' => array(), 
      ) 
     )) 
    ; 
} 

protected function configureSideMenu(MenuItemInterface $menu, $action, Admin $childAdmin = null) 
{ 
    if (!$childAdmin && !in_array($action, array('edit'))) { 
     return; 
    } 
    $admin = $this->isChild() ? $this->getParent() : $this; 
    $id = $admin->getRequest()->get('id'); 
    $menu->addChild('calculate', array('uri' => 'http://google.com?id=' . $id)); 
} 

및 SRC/MyApp를/MyBundle/자원/조회/관리에 list__action_calculate.html.twig라는 템플릿/넣어 :

{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %} 
<a href="{{ admin.generateObjectUrl('calculate', object) }}" class="calculate_link" title="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}"> 
    <img src="{{ asset('bundles/sonataadmin/famfamfam/page_white_edit.png') }}" alt="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}" /> 
</a> 
{% endif %} 

하지만 난 심포니에서이 오류를 가지고 :

An exception has been thrown during the rendering of a template 
("unable to find the route `mysite.mybundle.admin.myentity.calculate`") 
in "SonataAdminBundle:CRUD:list.html.twig" 
,536을

나는 무엇을 놓쳤는가? 이 페이지의 Doc보다 단서가 있습니까?

답변

6

마침내 얻었습니다!

protected function configureRoutes(RouteCollection $collection) 
{ 
    $collection->add('calculate'); 

} 

# Override to add actions like delete, etc... 
public function getBatchActions() 
{ 
    // retrieve the default (currently only the delete action) actions 
    $actions = parent::getBatchActions(); 

    // check user permissions 
    if($this->hasRoute('edit') && $this->isGranted('EDIT') && $this->hasRoute('delete') && $this->isGranted('DELETE')) 
    { 
     // define calculate action 
     $actions['calculate']= array ('label' => 'Calculate', 'ask_confirmation' => true); 

    } 

    return $actions; 
} 

protected function configureListFields(ListMapper $listMapper) 
{ 
    $listMapper 
     ->addIdentifier('id') 
     ->add('name')   
     // add custom action links 
     ->add('_action', 'actions', array(
      'actions' => array(
       'view' => array(), 
       'calculate' => array('template' => 'chemoinfoEdrugBundle:CRUD:list__action_calculate.html.twig'), 
       'edit' => array(), 
      ) 
     )) 
    ; 
} 

및 관리 컨트롤러 : 관리자 클래스에서

public function batchActionCalculate(ProxyQueryInterface $selectedModelQuery) 
{ 
    ... 
} 

와의/src에/내 사이트/mybundle/자원/뷰/CRUD :

{% if admin.isGranted('EDIT', object) and admin.hasRoute('edit') %} 
<a href="{{ admin.generateObjectUrl('calculate', object) }}" class="calculate_link" title="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}"> 
    <img src="{{ asset('bundles/sonataadmin/famfamfam/calculator.png') }}" alt="{{ 'action_calculate'|trans({}, 'SonataAdminBundle') }}" /> 
</a> 
{% endif %} 
+0

공식 문서 : [배치 작업] (http://sonata-project.org/bundles/admin/2-2/doc/reference/batch_actions.html) –

+0

새 문서 이동 od, 업데이트 주셔서 감사합니다. – user1254498