php - Manage translation fields in symfony form type generated with KnpLabs/DoctrineBehaviors and Translatable -


i'm new symfony , i'm using version 2.6

i wanted create translation products following https://github.com/knplabs/doctrinebehaviors#translatable

i ended with:

<?php  namespace khalibundle\entity;  use gedmo\mapping\annotation gedmo; use doctrine\orm\mapping orm; use knp\doctrinebehaviors\model ormbehaviors;  /**  * product  *  * @orm\table(name="products")  * @orm\entity  */ class product {     use ormbehaviors\translatable\translatable;      /**      * @var integer      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @gedmo\slug(fields={"name"}, updatable=false)      * @orm\column(length=255, unique=true)      */     private $slug;      /**      * @var integer      *      * @orm\column(name="status", type="smallint", length=1)      */     private $status;      /**      * @orm\manytoone(targetentity="category", inversedby="products")      * @orm\joincolumn(name="category_id", referencedcolumnname="id")      */     private $category;      /**      * id      *      * @return integer      */     public function getid()     {         return $this->id;     }      /**      * set slug      *      * @param string $slug      * @return product      */     public function setslug($slug)     {         $this->slug = $slug;          return $this;     }      /**      * slug      *      * @return string      */     public function getslug()     {         return $this->slug;     }      /**      * set status      *      * @param integer $status      * @return product      */     public function setstatus($status)     {         $this->status = $status;          return $this;     }      /**      * status      *      * @return integer      */     public function getstatus()     {         return $this->status;     }      /**      * set category      *      * @param \khalibundle\entity\category $category      * @return product      */     public function setcategory(\khalibundle\entity\category $category = null)     {         $this->category = $category;          return $this;     }      /**      * category      *      * @return \khalibundle\entity\category      */     public function getcategory()     {         return $this->category;     }      /**      *      */     public function __call($method, $arguments)     {         return $this->proxycurrentlocaletranslation($method, $arguments);     } } 

and producttranslation.php file

<?php  namespace khalibundle\entity;  use doctrine\orm\mapping orm; use knp\doctrinebehaviors\model ormbehaviors;  /**  * @orm\table(name="product_translations")  * @orm\entity  */ class producttranslation {     use ormbehaviors\translatable\translation;      /**      * @orm\column(type="string", length=255)      */     private $name;      /**      * @orm\column(type="string", length=255)      */     private $description;      /**      * set name      *      * @param string $name      * @return producttranslation      */     public function setname($name)     {         $this->name = $name;          return $this;     }      /**      * name      *      * @return string      */     public function getname()     {         return $this->name;     }      /**      * set description      *      * @param string $description      * @return producttranslation      */     public function setdescription($description)     {         $this->description = $description;          return $this;     }      /**      * description      *      * @return string      */     public function getdescription()     {         return $this->description;     } } 

and producttype.php

<?php  namespace khalibundle\form;  use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface;  class producttype extends abstracttype {     /**      * @param formbuilderinterface $builder      * @param array $options      */     public function buildform(formbuilderinterface $builder, array $options)     {         $builder             ->add('name')             ->add('slug')             ->add('status')             ->add('category')         ;     }      /**      * @param optionsresolverinterface $resolver      */     public function setdefaultoptions(optionsresolverinterface $resolver)     {         $resolver->setdefaults(array(             'data_class' => 'khalibundle\entity\product'         ));     }      /**      * @return string      */     public function getname()     {         return 'khalibundle_product';     } } 

but got exception:

neither property "name" nor 1 of methods "getname()", "name()", "isname()", "hasname()", "__get()" exist , have public access in class "khalibundle\entity\product". 

answer based on comments.

to not reinvent wheel can consider manage translations created using knplabs/doctrinebehaviors library it's translatable behavior togheter a2lix/translationformbundle. saves lot of time because have implemented common functionalities , it's use.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -