一种形式 - 添加到两个表
我如何在 Symfony 1.4 和 Doctrine 中制作一种表单,将数据添加到两个表中? 默认 Symfony 为一个表和模块生成表单。我什么时候可以编辑它并添加自己的字段? http://www.symfony-project.org/jobeet/1_4/Doctrine /zh/03 生成的。 例如,我想添加具有新类别的字段。
# config/doctrine/schema.yml
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
(...)
expires_at: { type: timestamp, notnull: true }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
此表单仅添加 id JobeetJob。我怎样才能添加到 JobeetCategory 中?
how can i in Symfony 1.4 and Doctrine make one form, that will add data to two tables?
Default Symfony generated form for one table and module. at which point I can edit it and add their own fields?
http://www.symfony-project.org/jobeet/1_4/Doctrine/en/03
generated.
i would like for example add field with new category.
# config/doctrine/schema.yml
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
JobeetJob:
actAs: { Timestampable: ~ }
columns:
category_id: { type: integer, notnull: true }
(...)
expires_at: { type: timestamp, notnull: true }
relations:
JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
this form add only id JobeetJob. how can i add into also JobeetCategory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将 JobeetCategory 关系嵌入到 JobeetJob 表单中。这将使您能够创建职位和类别。查找 sfForm 类的“embedRelation()̀”方法。
You can embed the JobeetCategory relation in the JobeetJob form. This will enable you to create a job and a category. Look for the `embedRelation()̀ method of the sfForm class.
您应该覆盖模型中的 save 方法(假设在 JobeetJob 模型中)。并将两个模型保存在事务中。下面我保存到产品和复合产品表。但不要忘记 save 方法应该有 2 个功能:插入 和 更新
}
You should override save method in your model(Lets say in JobeetJob model). And save both models in transaction. Below I save to product and composite product tables. But dont forget that save method should has 2 functionality : insert and update
}