php - Symfony 2.8 CollectionType Edit Issue? -


ok, have 3 tables, address, clients & clientaddress.

i have build abstracttype form address table, points address entity, so

class addresstype extends abstracttype {    public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->setmethod($options['method'])         ->add('house', texttype::class, ['label' => 'house'])         ->add('street', texttype::class, ['label' => 'street'])         ->add('city', texttype::class, ['label' => 'city']);   }    public function configureoptions(optionsresolver $resolver) {     $resolver->setdefaults(array(         'data_class' => 'xxxbundle\entity\addresses'     ));   } } 

i have abstracttype client address table, has 2 keys, client_id & address_id. client address form is

class clientaddresstype extends abstracttype {    public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->setmethod($options['method'])         ->add('clients_address', collectiontype::class,                                         ['label' => false,                                          'entry_type' => addresstype::class,                                          'allow_add' => true                                         ])          ->add('save', submittype::class, ['label' => 'save address',                                           'attr' => ['class' => 'buttonform']                                          ]);   }    public function configureoptions(optionsresolver $resolver) {     $resolver->setdefaults(array(         'data_class' => 'xxxbundle\entity\clientsaddresses'     ));   } } 

i render clientaddress form so,

{{ form_start(addaddress, {'attr': {'id': 'clientaddressform'}}) }}        {{ form_errors(addaddress) }}         {{ form_row(addaddress.clients_address.vars.prototype.house) }}        {{ form_row(addaddress.clients_address.vars.prototype.street) }}        {{ form_row(addaddress.clients_address.vars.prototype.city) }}  {{ form_end(addaddress) }} 

i know collections can added again , again using jquery, not want here, there no point, user not adding more 1 address.

i want embed address form client address abstract type , render using twig. way know of getting work without using jquery. - if there better way, please let me know.

but works, little editing submitted data, e.g. save address (all address in system have account id). data saves database.

now issue loading data collection user can edit address. edit path points new function,

    $clientaddress = $this->getdoctrine()                                                 ->getrepository('xxxbundle:clientsaddresses')                     ->find($id);      $clientform = $this->createform(clientaddresstype::class,                                         $clientaddress);      $clientform->handlerequest($request);      if($clientform->isvalid()) {         dump('vaild!');         die();     }      return $this->render('xxxbundle:clients\edit_address.html.twig', [                             'address' => $clientform->createview()                         ]); 

this function points new twig file, form rendered in same way, following error,

expected argument of type "array or (\traversable , \arrayaccess)" 

now clientaddress not setup arraycollection, because, 1. when saving new data adds errors, 2. did not think needed has collection 1 address, no need array hold data. - please correct me if wrong that!

so how data load same collection type form holds address form inputs, or wrong , have use else?

please help...

please try me if have not explain question right, hope have please give me time expand on question if need.

many thanks.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -