简体   繁体   中英

Symfony 4 easy admin how to create common action?

How to create common action like 'new' which will be do one action, for example send ajax request for get some kind of information. I'm trying add action via config/packages/easy_admin.yaml

easy_admin:
  entities:
    Users:    
      list:
        actions:
          - { name: 'refresh', label: 'Refresh', icon: 'sync' }

But it's add 'refresh' link for each row in my list.

I will be grateful for example or link on information.

That's not supported natively for now.

https://github.com/EasyCorp/EasyAdminBundle/issues/1400

You have to override the default list template to add your custom buttons:

{# /templates/bundles/EasyAdminBundle/default/list.html.twig #}

{% extends '@!EasyAdmin/default/list.html.twig' %}

{% block global_actions %}
    {{ parent() }}

    {# Add your code here, for example a button on the 'Users' list #}
    {% if _entity_config.name == "Users" %}
        <div class="button-action">
            <a class="btn btn-primary" href="#">Refresh</a>
        </div>
    {% 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