我正在使用embedRelation('ProductProperty')编辑产品及其当前属性。到目前为止一切都很好。这里的E / R图http://d.pr/1N7R
但是,现在我想根据其SetID拆分表单并在不同的AJAX选项卡中显示属性集。我仍然想要一个“保存”按钮,但如果我需要多个按钮,这并不重要。我怎么能这样做?
在我的_form.php中,我正在迭代集合,但我似乎无法获得ProductProperty表单对象的SetID。我是以错误的方式解决这个问题吗?
我正在使用symfony 1.4和Doctrine 1.2。这是我的schema.yml
Product:
tableName: products
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [title]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
category_id:
type: integer
notnull: true
sku:
type: string(50)
notnull: true
title:
type: string(150)
notnull: true
relations:
Category:
foreignType: many
foreignAlias: Products
Property:
tableName: properties
actAs:
Timestampable: ~
Sluggable:
unique: true
fields: [description]
canUpdate: true
columns:
id:
type: integer
primary: true
autoincrement: true
set_id:
type: integer
notnull: true
description:
type: string(100)
notnull: true
relations:
Set:
foreignType: many
foreignAlias: Properties
Set:
tableName: sets
actAs:
Timestampable: ~
columns:
id:
type: integer
primary: true
autoincrement: true
title:
type: string(100)
notnull: true
ProductProperty:
tableName: product_properties
actAs:
Timestampable: ~
columns:
product_id:
type: integer
primary: true
property_id:
type: integer
primary: true
value:
type: text
notnull: true
relations:
Product:
alias: Product
foreignType: many
foreignAlias: ProductProperties
onDelete: cascade
Property:
alias: Property
foreignType: many
foreignAlias: PropertyProperties
onDelete: cascade
答案 0 :(得分:0)
我设法在#symfony IRC频道(irc.freenode.net)上的dustin10的帮助下解决了这个问题。如果其他人需要它,这是解决方案:
我在ProductPropertyForm中添加了一个隐藏字段,其中包含我尝试在表单中检索的SetID:
$this->setWidget('property_set_id', new sfWidgetFormInputHidden());
$this->setDefault('property_set_id', $this->getObject()->getProperty()->getSetId());
$this->setValidator('property_set_id', new sfValidatorString());
这样我可以使用以下方法检索表单中的值:
$eForm['property_set_id']->getValue()
我现在用jQuery将我的表单分成多个选项卡:)再次,非常感谢dustin10的帮助。