0

我正在使用 embedRelation('ProductProperty') 以表格形式编辑产品及其当前属性。到目前为止一切都很好。E/R 图在这里http://d.pr/1N7R

但是,现在我想根据其 SetID 拆分表单并在不同的 AJAX 选项卡中显示属性集。我仍然想要一个“保存”按钮,但如果我需要多个按钮并不重要。我怎样才能做到这一点?

在我的 _form.php 中,我正在迭代 Sets,但我似乎无法获得 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
4

1 回答 1

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 的帮助。

于 2011-04-05T20:25:20.900 回答