一个小部件中的Symfony类别和子类别小部件

时间:2011-11-02 15:27:30

标签: symfony1 symfony-1.4 widget symfony-forms

我的架构中有两个关系,产品有很多子类别,产品有很多类别。所以我可以在 productForm.class.php

中制作
$this->widgetSchema['subcategory_list'] = new  sfWidgetFormDoctrineChoice(array('model' => 'Subcategory', 'add_empty' => false, 'multiple' => true,'expanded'   => true));

$this->widgetSchema['category_list'] = new  sfWidgetFormDoctrineChoice(array('model' => 'Category', 'add_empty' => false, 'multiple' => true,'expanded'   => true));

这是工作。但我需要举个例子:

类别1

子类别1,子类别2

类别2

类别3

subcategory3,subcategory4

我需要做,我可以检查类别和子类别。

谢谢!

UPD

Product:
  actAs:
    Timestampable: ~
    Sluggable:
      unique: true
      canUpdate: true
      fields: [name]
      builder: [myTools, StripText]
    I18n:
      fields: [name,description,shortbody,meta_keywords,meta_description]
  columns:
    partner_id:           { type: integer() }
    active:               { type: boolean, default: 0, notnull: false }
    name:                 { type: string(255), notnull: true }
    shortbody:            { type: string(500), notnull: true }
    description:          { type: string(), notnull: true }
    reference:            { type: string(100), notnull: true }
    code:                 { type: string(100), notnull: true }
    delivery_period:      { type: string(100), notnull: true }
    shipping_volume:      { type: string(100), notnull: true }    
    weight:               { type: string(100), notnull: true } 
    packing:              { type: string(100), notnull: true } 
    package_dimensions:   { type: string(100), notnull: true } 
    type_of_packaging:    { type: string(100), notnull: true } 
    video_url:            { type: string(100), notnull: false }
    meta_keywords:        { type: string(255) }
    meta_description:     { type: string(255) }
  relations:
    Subcategory:          { local: product_id , foreign: subcategory_id, refClass: ProductSubcategory } 
    Category:             { local: product_id , foreign: category_id, refClass: ProductCategory } 
    Partner:              { local: partner_id , foreign: id, onDelete: CASCADE }

ProductSubcategory:
  connection: doctrine
  columns:
    subcategory_id:  { type: integer(), primary: true}
    product_id:      { type: integer(), primary: true }
  relations:
    Product:         {  onDelete: CASCADE,local: product_id, foreign: id }
    Subcategory:     {  onDelete: CASCADE,local: subcategory_id, foreign: id }

ProductCategory:
  connection: doctrine
  columns:
    category_id:  { type: integer(), primary: true}
    product_id:   { type: integer(), primary: true }
  relations:
    Product:             {  onDelete: CASCADE,local: product_id, foreign: id }
    Category:            {  onDelete: CASCADE,local: category_id, foreign: id }

Category:
  actAs:
    Timestampable: ~
    Sluggable:
      unique: true
      canUpdate: true
      fields: [name]
      builder: [myTools, StripText]
    I18n:
      fields: [name]
  columns:
      name:   { type: string(255), notnull: true }

Subcategory:
  actAs:
    Timestampable: ~
    Sluggable:
      unique: true
      canUpdate: true
      fields: [name]
      builder: [myTools, StripText]
    I18n:
      fields: [name]
  columns:
    category_id:  { type: integer() }
    name:   { type: string(255), notnull: true }
  relations:
    Category: { onDelete: CASCADE,local: category_id , foreign: id }

ANSWER

我将它设为手动。我从缓存文件_form.php获取并重写它,添加类别和子类别复选框。比我在动作类中做了一些更改(手动设置和删除子类别和类别)。我使用来自答案的代码,所以我检查一下!

1 个答案:

答案 0 :(得分:0)