【发布时间】:2012-05-18 14:35:03
【问题描述】:
我正在尝试创建一个表单 Houses 并将图像表单嵌入其中。我已经按照教程http://www.symfony-project.org/more-with-symfony/1_4/en/06-Advanced-Forms。
我有以下架构:
houses:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
description: { type: string(5000), notnull: true }
images:
actAs: { Timestampable: ~ }
columns:
url: { type: string(255), notnull: true }
id_house: { type: integer, notnull: true }
relations:
houses: { local: id_house, foreign: id, foreignAlias: HousesImg}
和代码:
//lib/form/doctrine/ImagesCollectionForm
class ImagesCollectionForm extends sfForm
{
public function configure()
{
if(!$house= $this->getOption('house'))
{
throw new InvalidArgumentException('You must provide an house');
}
for ($i = 0; $i < $this->getOption('size',2); $i++)
{
$images = new images();
$images->house = $house;
$form = new imagesForm($images);
$this->embedForm($i, $form);
}
}
}
//lib/form/doctrine/housesForm.class.php
public function configure()
{
$form = new ImagesCollectionForm(null, array('house' => $this->getObject(),'size'=>2));
$this->embedForm('images', $form);
}
字段按预期显示。但是,当我按下保存按钮时,我得到一个空白页,并且数据没有保存在数据库中。
【问题讨论】:
-
您是否尝试使用 dev crontroler (
frontend_dev.php) 查看错误? -
你没有错字吗?
$images->house = $house;为$images->houses = $house; -
我发现了问题。在 imagesForm.class.php 中我没有添加 $this->useFields(...),并且 house_id 字段存在问题。现在它正在工作。
-
无论如何,谢谢你的重播
标签: forms symfony1 embed symfony-1.4