简体   繁体   English

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

[英]Symfony2 + Doctrine + FormType, relations and dynamic adding rows

first look: 第一眼: 在此处输入图片说明

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: 从phpMyAdmin向数据库添加内容或从代码显示数据都没有问题,但是当我尝试使用如下形式的formtype构建表单时:

  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) 与用户技能(技能,学位)的关系(现在我只能选择用户的现有技能,通过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). 在技​​能方面,他可以选择他知道的技能(例如C ++编程),单击“添加”,然后可以选择或输入学位(0 Begginer,1 ... 3 Expert)。 Adding more needs to be possible as with 3. and 2. 与3.和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. 在麦芽汁中,我将用几张JavaScript制作手册。

Thankyou 谢谢

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. 如果在表单构建器中添加allow_add选项,则可以使用Symfony将添加到表单中的prototype属性来执行allow_add

Collection Field Type 收集字段类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM