php - Product and Sizes symfony2 doctrine example -


i'm new symfony2 , i'm building first online store it. have products , want add product sizes, 1 product can have many sizes , 1 size can have many products. example: 2 products cat have 'm' size.

class product {     ...     /**      * @orm\manytomany(targetentity="size", inversedby="products", cascade={"persist", "merge"})      * @orm\jointable(name="sizes")      */     private $sizes; }  //in file class size {     /**      * @orm\manytomany(targetentity="product", mappedby="sizes")      */      protected $products; } 

productcontroller.php

...             ->add('sizes', collectiontype::class, [                 'entry_type' => sizetype::class,                 'label' => 'sizes',                 'allow_add'    => true,             ]) ... 

sizetype.php

public function buildform(formbuilderinterface $builder, array $options) {     $repo = $this->em->getrepository('appbundle:size');      $q = $repo->createquerybuilder('c')             ->getquery();      $sizes = $q->getresult();      $builder->add('name', entitytype::class, array(         'class' => 'appbundle:size',         'choice_label' => 'name',     )); } 

right i'm getting catchable fatal error: object of class appbundle\entity\size not converted string can fix if implement __tostring() don't know if right thing do, , if this, when editing product, dropdown doesn't select right size.

my question is, right way implement product - sizes function online store?

try code:

$builder->add('name', entitytype::class, array(     'class' => 'appbundle:size',     'choice_label' => 'name',     'property' => 'needed_property_name' //just write needed property name there )); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -