Symfony中嵌入表单的问题,如何使用三个表关系


Problems with embedded forms in Symfony, how to make it with three table relationships?

我试图在Symfony 1.4中使用嵌入式表单,但我遇到了表关系问题。我有一个User表、一个UserPhone表和一个PhoneType表。UserPhone与PhoneType相关,User与UserPhone相关。我如何从PhoneType访问一个字段?

这是我当前的,不工作的代码:

$subForm = new sfForm();
$userPhoneType = new PhoneType();
$userPhoneType->UserPhone->User = $this->getObject();
$form = new PhoneTypeForm($userPhoneType);
$subForm->embedForm(1, $form);
$this->embedForm('phone_description', $subForm); 

您可以像这样访问表单字段,其中"1"是嵌入表单键的名称:

$form['phone_description'][1]['field_name']->render();
$form['phone_description'][1]['field_name']->renderLabel();
$form['phone_description'][1]['field_name']->getValue();