Birden fazla form gösteren Symfony tek-çok embedrelation

0 Cevap php

Ben Symfony ile basit bir sorun olması gerektiğini yaşıyorum.

Bu örnekte ben bir kullanıcı, arıyordum, ve LookingForNames tablo var. Kullanıcı tablo kullanıcı hesabını tutan ve lookingfor ile bir ilişkisi var. Lookingfor tablo kullanıcı ve LookingForNames arasında herhangi bir ilişki tutar.

Örnek: Kullanıcı 'zincir', lookingfor ve LookingForNames gelen type_id dayalı LookingForNames masadan baktı olan, flört ve konuşmak için lookingfor tabloda iki girdileri olabilir.

Ben kullanıcı form içinde lookingfor için embedRelation zaman yaşıyorum sorundur. Kullanıcı onlar kalma ve konuşma arıyoruz seçti çünkü iki lookingfor formunu gösteriyor. Ben daha o kullanıcı için seçtiyseniz o kez daha göstermek istiyorum.

eg. of the problem

LookingFor Form - Instance #1
Dating - Checked
Talk - Not Checked
Friends - Not Checked

LookingFor Form - Instance #2
Dating - Not Checked
Talk - Checked
Friends - Not Checked

Çözüm kullanıcının seçimi önceden kalacağı bir onay kutusu biçiminde bir kez lookingfor tabloyu gösteriyor olacaktır.

eg. of the solution

LookingFor Form - Only One Instance
Dating - Checked
Talk - Checked
Friends - Not Checked

schema.yml

LookingFor:
  connection: doctrine
  tableName: looking_for
  columns:
    type_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    uid:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
  relations:
    LookingForNames:
      local: type_id
      foreign: type_id
      type: many
LookingForNames:
  connection: doctrine
  tableName: looking_for_names
  columns:
    type_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
  relations:
    LookingFor:
      local: type_id
      foreign: type_id
      type: many
User:
  connection: doctrine
  tableName: user
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    email:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    gender:
      type: string(6)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    age:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    city:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    state:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    country:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: true
      autoincrement: false
    profilepic:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      default: profileblank.jpg
      notnull: false
      autoincrement: false
  relations:
    LookingFor:
      local: id
      foreign: uid
      type: many
      foreignType: many

UserEditForm

class UserEditForm extends BaseUserForm
{
  public function configure()
  {
            $this->embedRelation('LookingFor');
  }
}

LookingForForm

class LookingForForm extends BaseLookingForForm
{
  public function configure()
  {
      $this->useFields(array('type_id'));
      $this->widgetSchema['type_id'] = new sfWidgetFormChoice(array(
          'choices' => Doctrine_Core::getTable('LookingForNames')->getFormChoiceNames(),
          'expanded' => true,
          'multiple' => true
       ));
   }
}

0 Cevap