我与symfony2一起工作,现在我尝试保存在实体中或直接在数据库中,创建在tag textext Jquery插件的texarea输入中创建的标签。 我不知道持久化值的好方法(注意,将来我想使用插件的Filter with Suggestions功能)。标签Textext jquery插件,一种保存symfony 2创建标签的好方法?
我觉得这个方法:
参加由插件创建的隐藏输入的输入值(在我的情况:
axxon_musicbundle_oeuvretype[tagz]
),与jQuery选择,所以:tagz = $('input [name * =“axxon_musicbundle_oeuvretype [tagz]”]')。val(); ex:= [“test”,“test2”,“test3”];
发送值通过AJAX控制器,具有
$('#form').submit(function()
{- 在控制器
变换值(例如:
["test","test2","test3"]
)到一个数组。 验证。
发送到数据库。
这里是我的作品映射实体的摘录,我想要保存该值。
/**
* @ORM\ManyToMany(targetEntity="tagz",cascade={"persist"})
* @ORM\JoinTable(name="oeuvre_tagz",
* joinColumns={@ORM\JoinColumn(name="oeuvre_id", referencedColumnName="id", nullable=false)},
* inverseJoinColumns={@ORM\JoinColumn(name="tagz_id", referencedColumnName="id", nullable=false)})
**/
private $tagz;
以我formtype:
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch ($options['flowStep']) {
...
case 5:
$builder->add('tagz', 'textarea', array(
'mapped' => false,
'required'=>false,
));
break;
我的观点,我使用的是多级形式,craue束:
{% if flow.getCurrentStep() == 5 %}
<script type="text/javascript">
$().ready(function() {
$('#axxon_musicbundle_oeuvretype_tagz').textext({ plugins: 'tags' });
$('#form').submit(function() {
$('form').get(0).setAttribute('action', '{{ path("axxon_music_ExtractFormTagz") }}');
var tagz = Array;
tagz =$('input[name*="axxon_musicbundle_oeuvretype[tagz]"]').val();
var actionController =$("#form").attr("action");
$.ajax({
type: 'POST',
data: {'tagz': tagz},
url: actionController,
success: function() {
$('form').get(0).setAttribute('action', '{{ path("axxon_music_add_oeuvre") }}');
... is this a good choice to do like that ?
});
});
</script>
<fieldset>
<legend>Etape {{ flow.getCurrentStep() }}/{{ flow.getMaxSteps() }}, Ajouter des mots clefs descriptifs
</legend>
<ul>
<li>
{{ form_row(form.tagz) }}
</li>
</ul>
{% include 'CraueFormFlowBundle:FormFlow:buttons.html.twig' %}
</fieldset>
{% endif %}
我的控制器,我想接收数据:
public function ExtractFormTagzAction(){
if ($this->getRequest()->isXmlHttpRequest()) {
$tagz = $this->getRequest()->request->get('tagz');
}
非常感谢。
非常感谢你,这似乎是聪明的,我会明天尝试这种方法,然后回复你。 – 2013-05-10 22:24:05
这似乎工作!我使用addViewTransformer()到我的tagformtype的buildForm函数中。现在,而不是通过变压器发送我的结果对象到一个setter,我搜索发送通过添加(arraycollection),一个想法? – 2013-05-13 17:45:37
你必须在你的实体中有getTagz()和setTagz() – Zeljko 2013-05-13 22:34:48