gpt4 book ai didi

symfony - 在 Sonata Admin 中编辑模型的模态窗口

转载 作者:行者123 更新时间:2023-12-04 15:44:23 27 4
gpt4 key购买 nike

如何在 SonataAdminBundle 中设置 Admin 类,以在模式窗口中显示用于添加/编辑实体的表单?像下面这样:

enter image description here

最佳答案

手动你可以自己做。

  • 添加您的配置服务
    calls:
    - [ setTemplate, [list, AcmeYourBundle:Your:base_list.html.twig]]
    - [ setTemplate, [edit, AcmeYourBundle:Your:base_edit.html.twig]]
  • 在您的管理包中,在 configureListFields 中添加自定义模板
    protected function configureListFields(ListMapper $listMapper) {
    $listMapper
    ->add('_action', 'actions', array(
    'actions' => array(
    'edit' => array('template' => 'AcmeYourBundle:Your:_action_edit.html.twig'),
    )
    ));
    }
  • _action_edit.html.twig
    {% if admin.hasRoute('edit') and admin.id(object) and admin.isGranted('EDIT', object)%}
    <a class="edit sonata-action-element" href="{{ admin.generateObjectUrl('edit', object) }}">
    <i class="fa fa-edit"></i>
    {{ 'link_action_edit'|trans({}, 'SonataAdminBundle') }}
    </a>
    {% endif %}
  • 在 base_list.html.twig 中添加 javascript 代码
    <script type="text/javascript">
    $(document).ready(function() {
    $('a.edit').click(function() { //bind handlers
    var url = $(this).attr('href');
    showDialog(url);
    return false;
    });

    $("#targetDiv").dialog({
    autoOpen: false,
    height: 700,
    width: 950,
    modal: true
    });

    function showDialog(url) {
    $("#targetDiv").load(url);
    $("#targetDiv").dialog("open");
    }
    });

    </script>
  • 完毕 !好好享受。
  • 关于symfony - 在 Sonata Admin 中编辑模型的模态窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22997550/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com