Symfony2表单类生成器
我从来没有尝试过构建这样的表单,所以我想看看是否有人能用Symfony的方式解决这个问题 下面的示例代码是减号注释和getter setter,只是为了节省空间:Symfony2表单类生成器,symfony,symfony-forms,Symfony,Symfony Forms,我从来没有尝试过构建这样的表单,所以我想看看是否有人能用Symfony的方式解决这个问题 下面的示例代码是减号注释和getter setter,只是为了节省空间: //Entity Class Location { private $id; private $name; // one to many annotation is here private $properties; } Class Property { priva
//Entity
Class Location {
private $id;
private $name;
// one to many annotation is here
private $properties;
}
Class Property {
private $id;
private $name;
// many to one
private $location
}
//Controller code
class SomeController {
//anotation for route etc ;)
public function someAction(Request $request){
//Returns all locations and there properties (only 4 locations)
$locations = $this->getDoctrine()->getRepository('LocationEntity')->findAllWithProperties();
$form = $this->createForm(new needHelpHereType(), $locations);
}
}
那么,我该如何创建一个执行以下操作的表单呢
此数组中的foreach实体为属性创建新集合类型。
所以,为了给你一个屏幕演示的想法,它会像这样
地点1的名称
位置1的属性集合
地点2的名称
位置2的属性集合
地点3的名称
位置3的属性集合
地点4的名称
位置4的属性集合
感谢您的帮助:我认为CollectionType是您的解决方案,
签出以下链接
我希望这能有所帮助。你好,莫塔姆姆。我已经记下了您的答案,因为您没有提供一个示例,说明如何在父级由实体数组集合而不是单个实体启动时使用它。请提供一个例子,我非常乐意更改您的分数: