0

Symfony 2 でフォームのオーバーラップに問題があります。フォト アルバムを含むアプリケーションを作成しようとしています。そのためには、アルバムを作成し、このプロセス中に彼の写真を追加する必要があります. 写真は1枚のみのアルバムとリンクしています。

私のコードはバックエンドにあると思いますが、写真のフォームはアルバムのフォーム内に表示されません。問題はフォーム自体にあると思います。

写真には、ファイルと名前という属性が必要です。

これが私のフォームです。

<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" />

何か考えはありますか?それとも問題はどこですか?

4

1 に答える 1

0

データ プロトタイプを手動で入力しているように見えますか? 「写真」がコレクションタイプであると仮定します。「allow_add」、「allow_delete」、および「prototype」オプションが true に設定されていることを確認します。

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

次に、 {{ form_row(form.photos) }} を実行するだけで、プロトタイプが自動的にレンダリングされます。

フォームの種類も投稿できれば、さらに役立ちます。

于 2012-05-31T18:08:01.087 に答える