Виджет категории и подкатегории Symfony в одном виджете - PullRequest
0 голосов
/ 02 ноября 2011

В моей схеме два отношения: продукт со многими подкатегориями и продукт со многими категориями.Так что я могу сделать в моем 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));

И это работа.Но мне нужно сделать, например:

category1

подкатегория 1, subcategory2

category2

category3

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 }

ОТВЕТ

Я делаю это вручную.Я беру из кеша файл _form.php и переписываю его, добавляю галочку категории и подкатегории.Чем я делаю некоторые изменения в классе действий (ручная установка и удаление подкатегорий и категорий).Я использую код из ответа, поэтому я проверяю его!

1 Ответ

0 голосов
/ 02 ноября 2011

отметьте это: http://www.symfony -project.org / jobeet / 1_4 / Doctrine / ru / 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();
   }
}

это должно работать нормально, но это не правильно программирование

...