dongzhan5246
2014-05-12 13:21
浏览 8
已采纳

Symfony2 + Doctrine + FormType,关系和动态添加行

first look: enter image description here

i have made this DB structure with entities than dumped and visualised.

Adding things to DB from phpMyAdmin or displaying data from code is no problem, but when i try to build form using formtype like:

  1. main form is CV (curriculum vitae)
  2. this contains one text field
  3. relation to skills of user (skill, degree) (now i can only select existing skill of the user, added through phpmyadmin)
  4. same as skills for employments, schools,..

my mind want to blow from weirdness. Can someone help me?

I want to build form where i can fill anything on one page. Eg.:

  1. user writes something about himself

  2. for example he clicks on add new school, and form for schools will appear, if he have more schools, he can add another (without reloading page and saving actual form)

  3. same with employments, click add new,...

  4. at skills he can select the skill he knows (for example C++ Programing), click add and than can select or enter the degree (0 Begginer, 1...3 Expert). Adding more needs to be possible as with 3. and 2.

  5. as final step he clicks on the "Save CV"

And anything done.

I have tried:

         ->add('skills', 'collection', array(
                'type' => new SkillsType(),
                'label' => 'Skills',
                'error_bubbling' => true,
                'cascade_validation' => true,
                    ))

With Template:

{{ form_start(form) }}
{% for skill in form.skills %}
    <li>
        {{ form_widget(skill) }}
    </li>
{% endfor %}
{{ form_end(form) }}

to add skills then i wanted to use the same for adding employments.

At wort i will make manual form with couple of javascript.

Thankyou

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtn913117 2014-05-12 14:13
    已采纳

    The Collection field type is what your using. If you havent already its work looking at the Documentation for it.

    You can do what you want by using the prototype property which Symfony will add to your form if you add the allow_add option in your form builder.

    Collection Field Type

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题