简体   繁体   中英

data of dataGrid in SonataAdmin bundle

I try to get the value of a field I configure in my class that extends Admin in function configureFormFields. I want to attach it as a parameter for custom action I created. any idea how to fetch it? I want to change 'test' to a value according to a field in a row in the admin.

The Admin code

protected function configureListFields(ListMapper $list) {
    $list ->add('_action','actions',array('actions' => array('run' => array('template' => 'AcmePortalBundle:Files:action.html.twig'), ))) 
        ->addIdentifier('name') 
        ->add('serverPath'); } 

The twig template action.html.twig

{ % if admin.isGranted('EDIT', object) and admin.hasRoute('edit') % } 
<a href="{{ path('upload', {'t': 'test' }) }}"> 
  <img src="{{ asset('bundles/sonataadmin/famfamfam/server_connect.png') }}" /> 
</a>
{ % endif % }

Datagrid value is in in variable "value" :) Extend base list field and use value in template. Don't forget to test empty value

{% extends admin.getTemplate('base_list_field') %}

{% block field%}
    {%- if value is empty -%}
    &nbsp; //or something other
    {%- else -%}
        <a href="{{ path('upload', {'t': value }) }}"> 
        ....
    {%- endif -%}
{% endblock %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM