Symfony1 关于如何在Symfony中嵌入表单的示例
我在Ubuntu 9.10上使用Symfony 1.3.2和推进ORM 我有一个用户配置文件表,其中有许多其他表链接到它(即user_profile.id是许多其他表中的FK) 我的数据库模式如下所示:Symfony1 关于如何在Symfony中嵌入表单的示例,symfony1,symfony-forms,Symfony1,Symfony Forms,我在Ubuntu 9.10上使用Symfony 1.3.2和推进ORM 我有一个用户配置文件表,其中有许多其他表链接到它(即user_profile.id是许多其他表中的FK) 我的数据库模式如下所示: user_profile: _attributes: { phpName: UserProfile } id: ~ guard_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id, requi
user_profile:
_attributes: { phpName: UserProfile }
id: ~
guard_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true }
address: { type: longvarchar, required: true }
vehicle_type:
_attributes: { phpName: VehicleType }
id: ~
name: { type: varchar(32), required: true }
user_vehicle:
_attributes: { phpName: UserVehicle }
id: ~
user_id: { type: integer, foreignTable: user_profile, foreignReference: id, required: true }
vehicle_type: { type: integer, foreignTable: vehicle_type, foreignReference: id, required: true }
license_plate: { type: varchar(16), required: true }
user_child:
_attributes: { phpName: UserChild }
id: ~
user_id: { type: integer, foreignTable: user_profile, foreignReference: id, required: true }
gender: { type: boolean, required: true }
name: { type: varchar(32), required: true }
我希望将链接到用户配置文件对象的其他对象嵌入到用户配置文件表单中,以便在对用户配置文件表单执行CRUD时,相关对象(例如UserVehicle、UserJob)也与用户配置文件对象同时被CRUD
我需要一个简单的代码片段来说明如何:
//lib/form/doctrine/ProductForm.class.php
公共函数配置()
{
$subForm=new sfForm();
对于($i=0;$i<2;$i++)
{
$productPhoto=新的productPhoto();
$productPhoto->Product=$this->getObject();
$form=新的ProductPhotoForm($productPhoto);
$subForm->embedForm($i,$form);
}
$this->embedForm('newPhotos',$subForm);
}
对于创建/删除/更新部分,可能会提供一些帮助。您阅读了吗?:
//lib/form/doctrine/ProductForm.class.php
公共函数配置()
{
$subForm=new sfForm();
对于($i=0;$i<2;$i++)
{
$productPhoto=新的productPhoto();
$productPhoto->Product=$this->getObject();
$form=新的ProductPhotoForm($productPhoto);
$subForm->embedForm($i,$form);
}
$this->embedForm('newPhotos',$subForm);
}
对于创建/删除/更新部分,可能会提供一些帮助。我从未发现官方方法适合我的需要。我开发了一种完全不同的方法。在我以前工作的公司,我们在生产中使用了这种方法,发现它更具弹性和简单。关键概念是“不要使用Symfony的表单类,您会发现嵌入表单可能是一项非常简单的任务”
我希望这能帮助您嵌入表单。我从未发现官方方法适合我的需要。我开发了一种完全不同的方法。在我以前工作的公司,我们在生产中使用了这种方法,发现它更具弹性和简单。关键概念是“不要使用Symfony的表单类,您会发现嵌入表单可能是一项非常简单的任务。” 我希望这能帮助你嵌入表单
// lib/form/doctrine/ProductForm.class.php
public function configure()
{
$subForm = new sfForm();
for ($i = 0; $i < 2; $i++)
{
$productPhoto = new ProductPhoto();
$productPhoto->Product = $this->getObject();
$form = new ProductPhotoForm($productPhoto);
$subForm->embedForm($i, $form);
}
$this->embedForm('newPhotos', $subForm);
}