问题描述
如果您使用控制台为Symfony2中的实体创建CRUD代码,则最终将创建一个非常基本的删除函数。
If you create CRUD-code for an entity in Symfony2 using the console, you will end up with a very basic delete function.
此函数精益高效,但不提供你确定吗? - 确认。如果要删除的实体存在,则会立即删除。
This function is lean and efficient, but does not provide an "are you sure?"-confirmation. If the entity to be deleted exists, it will be deleted immediately.
有没有人为添加用户确认的最简单方法提出建议?
Does anyone have suggestions for the easiest way to add user confirmation?
到目前为止我一直在使用:
Up until now I have been using:
- 一个额外的控制器功能
- jQuery
看起来有点奇怪,但是Symfony2没有内置的选项。
It seems a bit weird though that Symfony2 would have no built-in option for this. Anyone better ideas?
推荐答案
您还可以使用附加属性呈现表单的基本删除字段:
You could also render the basic delete-field of your form with an additional attribute:
在您的Twig模板内:
Inside your Twig-Template:
{{ form(delete_form, {'attr': {'onclick': 'return confirm("Are you sure?")'}}) }}
这篇关于什么是添加“确认选项”的最佳方式。到Symfony2中的删除表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!