Administratorning generatsiya doktrinasi shaklini o'zgartirish tartibi

Quyidagilardan iborat bo'lgan Ma'muriy Jeneratorning Doctrine Formasini o'zgartirish kerak:

$this->embedRelation('MyRelation');

Standart tartib quyidagicha:

Screenshot 1

Maqsad - tanlovning har bir elementi alohida satrda matn ko'rinishida, shuningdek, narx va miqdordan:

Screenshot 2

schema.yml

Game:
    actAs:
      Timestampable: ~
    columns:
      id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
      game_name: { type: string(100), notnull: true }
    indexes:
      it:
  fields: game_name
  type: unique

  Campaign:
    actAs:
      Timestampable: ~
    columns:
      id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
      name: { type: string(100), notnull: true }
      is_active: { type: boolean, notnull: true, default: 0 }
      start: { type: datetime, notnull: true }
      end: { type: datetime, notnull: true }
    relations:
      CampaignMatrix: { onDelete: CASCADE, local: id, foreign: campaign_id, foreignAlias: CampaignMatrixCampaign }

  CampaignGames:
    actAs:
      Timestampable: ~
    columns:
      id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
      campaign_id: { type: integer(4), notnull: true, unsigned: true }
      game_id: { type: integer(4), notnull: true, unsigned: true }
    indexes:
      tc:
  fields: [campaign_id, game_id]
  type: unique
    relations:
      Campaign: { onDelete: CASCADE, local: campaign_id, foreign: id, foreignAlias: CampaignCampaignGames }
      Game: { onDelete: CASCADE, local: game_id, foreign: id, foreignAlias: GameCampaignGames }

  CampaignMatrix:
    actAs:
      Timestampable: ~
    columns:
      id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
      item_id: { type: integer(4), notnull: true, unsigned: true }
      campaign_id: { type: integer(4), notnull: true, unsigned: true }
      price_id: { type: integer(4), notnull: true, unsigned: true }
      quantity: { type: integer(4), notnull: true, unsigned: true }
    relations:
      Item: { onDelete: CASCADE, local: item_id, foreign: id, foreignAlias: ItemCampaignMatrix }
      Campaign: { onDelete: CASCADE, local: campaign_id, foreign: id, foreignAlias: CampaignCampaignMatrix }
      Price: { onDelete: CASCADE, local: price_id, foreign: id, foreignAlias: PriceItems }

  Price:
    columns:
      id: { type: integer(4), unsigned: true }
      currency_code: { type: string(3), notnull: true }
      price: { type: float, notnull: true }
    indexes:
      tc:
  fields: [id, currency_code]
  type: unique

  Item:
    actAs:
      Timestampable: ~
      I18n:
  fields: [name, description, image]
    columns:
      id: { type: integer(4), primary: true, autoincrement: true, unsigned: true }
      game_id: { type: integer(4), notnull: true, unsigned: true }
      product_id: { type: string(100), notnull: true }
      price_id: { type: integer(4), notnull: true, unsigned: true }
      quantity: { type: integer(4), notnull: true, unsigned: true }
      name: { type: string(100), notnull: true }
      description: { type: string(255), notnull: true }
      image: { type: string(255), notnull: true }
    indexes:
      it:
  fields: item_type
    relations:
      Game: { onDelete: CASCADE, local: game_id, foreign: id, foreignAlias: GameItems }
      Price: { onDelete: CASCADE, local: price_id, foreign: id, foreignAlias: PriceItems }

Men shunday qilaman:

$list = MainItemTable::getInstance()->findByGameId($gameId);

$CampaignMatrix = new CampaignMatrix();

foreach($list as $index => $item) {

    $itemAssocForm = new CampaignMatrixForm($CampaignMatrix);
    $itemAssocForm->item_id = $item->getId();//Need it in the form as hidden field
    $this->embedForm($item->getProductId(), $itemAssocForm);
}

Va shuning uchun men qiymatni olishga harakat qilaman:

$this->widgetSchema['item_id'] = new sfWidgetFormInputText(array(), array('value' => $this->item_id));//It doesn't get the Id

Lekin xato bor: Muhim xato: 30 soniyada maksimal ijro muddati 237-bandda /vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Relation/Parser.php dan oshib ketdi.

  1. Price_id ni CampaignMatrixFormda o'rnatmasam, hech qanday xato paydo bo'lmadi. "Loop" dagi har bir mahsulot satri uchun bir xil ma'lumotlarning tanlanganini bajarmaslik
  2. Mahsulot identifikatori yo'q, lekin uni yashirin maydonga kerak. CampaignMatrixFormga joriy qatordagi CampaignMatrix identifikatoridan qanday o'tish kerak?
0
Savolim ^ ni yangiladim
qo'shib qo'ydi muallif Roman Newaza, manba
tegishli jadvallarni diagramma orqali joylashtirasizmi?
qo'shib qo'ydi muallif yitznewton, manba

3 javoblar

Assotsiatsiya shaklini ota-forma bilan to'ldirish uchun assotsiatsiyaga o'tishingiz kerak. Agar siz schema.yml qismini joylashtirsangiz, bu oddiy bo'ladi.

Ushbu snippetni qayta ishlatishga harakat qiling:

$list = MyRelatedObjectTable::getInstance()->findAll();

foreach($list as $item)
{
  $itemAssoc = AssociationTable::getInstance()->findByObjectId($this->object->id, $item->id);

  if(!$itemAssoc)
  {
    $itemAssoc = new Association();
    $itemAssoc->value_id = $itemAssoc->id;
    $itemAssoc->user_id = $this->object->id;
  }

  $itemAssocForm = new AssociationForm($itemAssoc);
  $this->embedForm('itemAssoc'.$item->code, $itemAssocForm);
}
1
qo'shib qo'ydi
Xo'sh, preference_id va user_id-ga qanday qilib kirish mumkin?
qo'shib qo'ydi muallif Roman Newaza, manba
Hechqisi murakkab emas ;-)
qo'shib qo'ydi muallif Roman Newaza, manba
Ma'lumotlarimni ariza bilan yangilab bo'lmadi, faqat qo'shib qo'ydim ... Qo'shilgan narsalar ko'milgan shaklda oldindan tanlanmadi. Menga o'xshash ko'zoynaklar uni mutlaqo odatiy qilish kerak. Menimcha AJAX yordam beradi.
qo'shib qo'ydi muallif Roman Newaza, manba
Sizning modelingiz, ehtimol, juda murakkab ... CampaignGames-da CampaignMatrixni qayta ishlashga harakat qiling. Maqsadingizga erishish uchun siz o'zingizning maxsus formalarni yaratish va qayta ishlashga chuqur sarmoya kiritishingiz kerak. Maxsus form sinfni yaratib, maxsus widget'larni va widgetSchema'ni yuklang. Qayta ishlash uchun o'zingizning mashq qiling va doktrin objetcni yangilash uchun usulni saqlang. EmbedForm yomon dizayndan aziyat chekadi va ehtimol sizning maqsadingizga mos kelmaydi.
qo'shib qo'ydi muallif dxb, manba

siz keshdan kodni olishingiz va backend/modules/nameAPP va keyingi tahrir shabloniga o'tishingiz mumkin

0
qo'shib qo'ydi
Ushbu doktrin shaklidir. O'ylaymanki, yaxshi yo'l bo'lishi kerak.
qo'shib qo'ydi muallif Roman Newaza, manba

Buning eng yaxshi usuli - bunga qisman kirishdir. Forma sinfidagi element uchun tanlangan qutini unset yoki sizning uyushmalaringizni yo'qotishingiz kerakligini unutmang. Agar sizga ko'proq yordam kerak bo'lsa, men bu haqida batafsil ma'lumotga ega bo'lamiz.

0
qo'shib qo'ydi
agar bu topshiriqni bajarishda ushbu sohada ma'lumot yo'q bo'lsa (vidjet ko'rsatilmaydi), bo'sh joyni topshirishga o'xshaydi. Bu qiymatni tozalaydi. Ammo , eng yaxshi variant, maydonni sfWidgetFormInputHidden ga o'zgartiradi - bu assotsiatsiyani saqlab qoladi va qiymatni yo'qotishning oldini oladi.
qo'shib qo'ydi muallif samura, manba
Ob'ektni tanlay olmasam, nima uchun uylanish yo'qoladi?
qo'shib qo'ydi muallif Roman Newaza, manba
Men savolni yangiladim
qo'shib qo'ydi muallif Roman Newaza, manba