2012-05-31 46 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)}},它應該呈現雛形自動。

如果您可以發佈您的表單類型,它將有助於更多。