【发布时间】:2012-06-08 07:19:10
【问题描述】:
是否可以从 2 个连接的实体对象构建一个表单?
我有两个实体property 和propertylanguage,它们以onetomany 关系连接。
(一个属性可以有多种语言)
语言有 title 和 description 列。
所以一个属性可以有英文、法文、德文标题。
我正在尝试构建一个表单。 见下文。
控制器: addProperty.php
class AddPropertyController extends Controller
{
// ....
public function indexAction(Request $request)
{
$property = new property;
$language = new propertyLanguage;
$property ->addpropertylanguage($language);
$form = $this->createForm(new propertyType($this->getDoctrine()),$property);
// .....
}
表单类型:propertType.php
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('title', 'text');
// other ->add() below.
}
它返回以下错误:
既不是属性“title”,也不是方法“getTitle()”,也不是方法 “isTitle()”存在于类“\defaultBundle\Entity\property”中
当然在property中没有属性Title,但是在propertylanguage中有一个.. 即使我尝试: ->add('title', 'entity', array('class'=>defaultBundle:propertylanguage)); 它不起作用。
感谢您有时间帮助我。
最好的,
皮埃尔。
【问题讨论】:
标签: symfony doctrine-orm