2011-11-02 50 views
0

我在我的模式中有兩個關係,產品有許多子類別和有很多類別的產品。所以,我可以讓我的productForm.class.phpSymfony類別和子類別小部件在一個小部件中

$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,subcategory2

產品組別

類別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中獲取並重寫它,添加類別和子類別複選框。比我在操作類中做了一些更改(手動設置和刪除子類別和類別)。我使用答案代碼,所以我檢查它!

回答

0

檢查:http://www.symfony-project.org/jobeet/1_4/Doctrine/en/06

更新:

,你可以很簡單的模板:

$categories = CategoryTable::getInstance()->findAll(); 

foreach ($categories as $category) { 
    echo $category->getName(); 
    $subcategory = SubcategoryTable::getInstance()->findBy('category_id', $category->getId()); 
    foreach($subcategory as $sub){ 
     echo $sub->getName(); 
    } 
} 

這應該工作正常,但是這個心不是正確編程

+0

什麼的一部分? – denys281

+0

主頁上的分類 –

+0

這不是解決我的問題... – denys281