有关如何在 Symfony 中嵌入表单的示例
我在 Ubuntu 9.10 上使用 Symfony 1.3.2 和 Propel ORM。
我有一个用户配置文件表,其中有许多其他表链接到它(即 user_profile.id 是许多其他表中的 FK。
我的数据库架构如下所示:
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 }
我想嵌入链接到用户配置文件的其他对象 ,相关对象(例如 UserVehicle、UserJob 也与用户配置文件对象同时进行 CRUD)。
对象,在用户配置文件表单中,以便当我对用户配置文件表单执行 CRUD时 演示如何:
- 将各种相关对象(即 UserVehicle、UserChild)嵌入到 UserProfile 表单中
- 在执行操作时创建/更新/删除各种相关对象(请注意,一个用户可以拥有 0-N 多个车辆或孩子分配给他们
I am using Symfony 1.3.2 with Propel ORM on Ubuntu 9.10.
I have a user profile table, which has many other tables linked to it (i.e. user_profile.id is a FK in many other tables.
My db schema looks something like this:
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 }
I would like to embed the other objects that link to the user profile object, in the user profile form, so that when I am performing CRUD on a user profile form, the related objects (e.g. UserVehicle, UserJob are also CRUD at the same time as the user profile object).
I need a simple snippet that will show how to:
- Embed the various related objects (i.e. UserVehicle, UserChild) into the UserProfile form
- Create/Update/Delete the various related objects as the operation is being carried (please note, a user can have more than 0-N vehicles or children assigned to them
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否阅读过文档?:
对于创建/删除/更新部分,这篇文章可能会提供一些帮助。
Have you read the documentation?:
For the create/delete/update part, this article might give some help.
我从未找到适合我需求的官方方法。我开发了一种完全不同的方法。在我曾经工作的公司中,我们在生产中使用 这种新方法,发现它更有弹性和简单。关键概念是“不要使用 Symfony 的 Form 类,你会发现嵌入表单可以是一个非常简单的任务”
我希望这可以帮助您嵌入表单。
I never found the official approach right for my needs. I developed a completely different approach. In the company where I used to work we used in production this new approach, finding it a bit more elastic and simple. The key concept is "don't use Symfony's Form class and you will discover that embedding forms can be a very simple task"
I hope this can help you embedding forms.