doctrine - Double listing not working in Symfony 1.4 embedded form -


i'm struggling simple form working in symfony 1.4 backend module.

the idea create embedded form (one many relation, inschrijvingen -> danser). each embedded form has 1 many many relation. (lessen) forms displays correctly doesn't save lessen_list. (many many relation)

the danserform i'm embedding work on own. doesn't work when embedding inschrijvingenform.

i tried following tutorial. didn't work me: http://inluck.net/blog/many-to-many-relations-in-embedded-form-in-symfony-1_4

my schema.yml

inschrijving:   actas:     timestampable: ~   columns:     voornaam: { type: string(100), notnull: true, minlength: 2 }     achternaam: { type: string(100), notnull: true, minlength: 2 }     straat: { type: string(100), notnull: true, minlength: 2 }     nr: { type: string(5) }     postcode: { type: int(9), notnull: true, minlength: 4 }     gemeente: { type: string(100), notnull: true, minlength: 2 }     land: { type: string(2), notnull: true, default: 'be' }     telefoon: { type: string(100), notnull: true, minlength: 8 }     email:  { type: string(100), notnull: true, minlength: 4, nospace: true }     gestructureerde_mededeling: { type: string(20) }     interne_opmerking: { type: string(1000) }     gebruiker_id: { type: int(9) }     is_gearchiveerd:  { type: boolean, default:false }   relations:     danser:       local: id       foreign: inschrijving_id       type: many       ondelete: cascade       foreignalias: dansers  danser:   columns:     voornaam: { type: string(100), notnull: true, minlength: 2 }     achternaam: { type: string(100), notnull: true, minlength: 2 }     geboortedatum: { type: date(), notnull: true }     email:  { type: string(100), notnull: true, minlength: 4, nospace: true }     medische_opmerkingen: { type: string(2000) }     inschrijving_id: { type: int(9), notnull: true }     is_verzekering_ok: { type: boolean, default:false }   relations:     inschrijving:       local: inschrijving_id       foreign: id       type: 1       ondelete: cascade       foreignalias: inschrijvingen     lessen:       class:              lessen       refclass:           lessenvandanser       local:              danser_id       foreign:            lessen_id  lessenvandanser:   columns:     lessen_id:             { primary: true, type: integer }     danser_id:            { primary: true, type: integer }   relations:     lessen:                { ondelete: cascade, local: lessen_id, foreign: id ,class: lessen}     danser:          { ondelete: cascade, local: danser_id, foreign: id, class: danser }  lessen:   actas:     timestampable: ~   columns:     naam: { type: string(100), notnull: true, minlength: 2 }     leeftijd_van: { type: string(3) }     leeftijd_tot: { type: string(3) }     dag:  { type: enum(),values: ['maandag','dinsdag','woensdag','donderdag','vrijdag','zaterdag'],default: maandag }     van: { type: time() }     tot: { type: time() }     beschrijving: { type: string(5000) }     max_aantal_deelnemers: { type: int(9) }         lesgever_id: { type: int(9), notnull: true }     locatie_id: { type: int(9), notnull: true }     lessenreeks_id: { type: int(9), notnull: true }   relations:     danser:       class:              danser       refclass:           lessenvandanser       local:              lessen_id       foreign:            danser_id 

inschrijvingenform.class.php

<?php class inschrijvingform extends baseinschrijvingform {   public function configure()   {       unset(       $this['created_at'], $this['updated_at'],$this['gestructureerde_mededeling']       );        $choices = countrycodes::get();       $this->widgetschema['land'] = new sfwidgetformchoice(array('choices' => $choices));        $choice_keys = array();       foreach ($choices $choice) {           $choice_keys = array_merge($choice_keys,array_keys($choice));       }        $this->setvalidator('land', new sfvalidatorchoice(array('choices'=>$choice_keys,'required'=>true)));       $this->setdefault('land','be');        //many many relations       $data = $this->getobject();       $data_count = @count($_post['inschrijving']['danser']);       $data_count = $data_count > 0 ? $data_count:1;          $subform = new sfform();          ($i = 0; $i < $data_count; $i++){             if($data['danser'][$i]){                 $subform->embedform($i, new danserform($data['danser'][$i]));             }else{                 $subform->embedform($i, new danserform());             }         }         $this->embedform('danser', $subform);   }    public function saveembeddedforms($con = null, $forms = null) {         if (null === $forms){             $en_forms = $this->getembeddedform('danser');              foreach ($en_forms $name => $form){                 if ($form instanceof sfformobject){                     $form->getobject()->setinschrijvingid($this->getobject()->getid());                     $form->getobject()->save($con);                 }             }         }           return parent::saveembeddedforms($con, $forms);     } } 

danserform.class.php

<?php  /**  * danser form.  *  * @package    dansschool  * @subpackage form  * @author     ilias barthelemy  * @version    svn: $id: sfdoctrineformtemplate.php 23810 2009-11-12 11:07:44z kris.wallsmith $  */ class danserform extends basedanserform {   public function configure()   {       unset(       $this['inschrijving_id']       );        $years = range(((int) date('y'))-70, ((int) date('y'))-3);       $years_list = array_combine($years, $years);        //$this->setwidget('geboortedatum', new sfwidgetformdate(array('format' => '%day%/%month%/%year%','years' => $years_list)));       $user = sfcontext::getinstance()->getuser();       $inschrijving = $user->getattribute( 'dansers_form.inschrijving',null,'admin_module' );        if(!is_null($inschrijving)){           $this->widgetschema['inschrijving_id']->setdefault($inschrijving['inschrijving_id']);       }        $this->setwidget('geboortedatum',new sfwidgetformjquerydate(array(         'date_widget' => new sfwidgetformdate(array('format' => '%day%/%month%/%year%','years' => $years_list))       )));        $this->widgetschema['lessen_list'] = new sfwidgetformdoctrinechoice(array(       'multiple' => true,       'model' => 'lessen',       'renderer_class' => 'sfwidgetformselectdoublelist',       'renderer_options' => array(         'label_unassociated' => 'beschikbare lessen',         'label_associated' => 'actief'     )));    }      public function bind(array $taintedvalues = null, array $taintedfiles = null)     {         if($this->getobject()->getid()>0){             $taintedvalues['id']=$this->getobject()->getid();             $this->isnew = false;         }         parent::bind($taintedvalues, $taintedfiles);     } } 

is lessen_list field in basedanserform , baseinchrijvingform class? symfony provides widget managing many-to-many relationships 1 have in base class. thought named lessenvandanser_list.

i don't think you're embedding danser forms correctly. try similar i've done below, assign danser objects inschrijving object, before instantiating embedded forms danser objects. i've done create new dansercollectionform class handle logic (see below).

// lib\form\dansercollectionform.class.php class dansercollectionform extends sfform {     if (!$inschrijving = $this->getoption('inschrijving')) {         throw new invalidargumentexception(sprintf("%s must provided inschrijving object", get_class($this)));     }      // danser objects associated inschrijving     $dansers = $inschrijving->getdansers();      // if no dansers, creat new danser     if (!$dansers) {         $danser = new danser();         // assign danser inschrijving         $danser->inschrijving = $inschrijving;         $dansers = array($danser);     }      // embed danser forms     foreach ($dansers $key => $danser) {         $this->embedform($key, new danserform($danser));     } } 

then in inschrijvingform class

// lib\form\inschrijvingform.class.php  class inschrijvingform extends baseinschrijvingform {     public function configure()     {         unset(             $this['created_at'],             $this['updated_at'],             $this['gestructureerde_mededeling']         );          $choices = countrycodes::get();         $this->widgetschema['land'] = new sfwidgetformchoice(array('choices' => $choices));          $choice_keys = array();         foreach ($choices $choice) {                 $choice_keys = array_merge($choice_keys,array_keys($choice));         }          $this->setvalidator('land', new sfvalidatorchoice(array('choices' => $choice_keys, 'required' => true)));         $this->setdefault('land','be');          $collectionform = new dansercollectionform(null, array('inschrijving' => $this->getobject()));         $this->embedform('dansers', $collectionform);     }      public function saveembeddedforms($con = null, $forms = null)     {         if (null === $forms) {             $dansers = $this->getvalue('dansers');             $forms = $this->embeddedforms;              foreach ($this->embeddedforms['dansers'] $name => $form) {                 $deletedanser = // put logic of whether ignore/delete danser forms here                 if ($deletedanser) {                     unset($forms['dansers'][$name]);                     $form->getobject()->delete();                 }             }         }          return parent::saveembeddedforms($con, $forms);     } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -