2012-05-31 118 views
0

我在Symfony 2中有一个重叠表单的问题。我试图用照片相册创建一个应用程序。 为此,我需要在此过程中创建一个相册并添加他的照片。 照片链接onl一个相册。重叠表格

我认为我的代码是正确的后端,但照片的形式从来没有显示在专辑的形式。我认为问题在于他自己的形式。

照片必须属性:文件和名称。

这是我的表格。

<script type="text/javascript"> 
$(document).ready(function() { 
    var $container = $('#thelink_albumbundle_albumtype_photos'); 

    function add_photo() { 
     index = $container.children().length; 

     $container.append(
       $($container.attr('data-prototype').replace(/\$\$picture\$\$/g, index)) 
     ); 
    } 

    if($container.children().length == 0) 
     add_tag(); 


    $('#add_photo').click(function() { 
     add_photo(); 
    }); 
}); 

<form method="post" enctype="multipart/form-data"> 
{{ form_widget(form) }} 


<div id="thelink_albumbundle_albumtype_photos" data-prototype="&lt;div&gt; 
    &lt;label class=&quot; required&quot;&gt;$$photo$$&lt;/label&gt; 
    &lt;div id=&quot;thelink_albumbundle_albumtype_photos$$photo$$&quot;&gt; 
    &lt;div&gt;&lt;label for=&quot;thelink_albumbundle_albumtype_photos$$photo$$_photo&quot; 
    class=&quot; required&quot;&gt;Photo&lt;/label&gt; 
    &lt;input type=&quot;file&quot; id=&quot;thelink_albumbundle_albumtype_photos$$photo$$_photo&quot; 
    name=&quot;thelink_albumbundle_albumtype[photos][$$photo$$][picture]&quot; required=&quot;required&quot; 
    maxlength=&quot;255&quot; value=&quot;&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"> 
</div> 

<br /> 

<a href="{{ path('TheLinkAlbumBundle_index') }}" title="Retourner sur la liste des Albums"> 
    Annuler la {% if news is defined %}Modification{% else %}Création{% endif %} 
</a> 

<input type="submit" value="{% if album is defined %}Modifier{% else %}Créer{% endif %} l'Album" /> 

你有什么想法?或者问题在哪里?

回答

0

它看起来像你手动输入数据原型?假设“照片”是一种集合类型。请确保你有“allow_add”,“allow_delete”和“原型”选项设置为true:

->add('photos', 'collection', array(
     'type'    => new PhotoType(), 
     'allow_add'   => true, 
     'allow_delete'  => true, 
     'prototype'   => true 
    )) 

然后,你可以做{{form_row(form.photos)}},它应该呈现雏形自动。

如果您可以发布您的表单类型,它将有助于更多。