php - Error sonata classificiation bundle -


i have problem. installed sonata classification bundle.

but when want create new post have error:

neither property "collection" nor 1 of methods "getcollection()", "collection()", "iscollection()", "hascollection()", "__get()" exist , have public access in class "dn\sitebundle\entity\post".*

this code in postadmin.php (src/dn/sitebundle/admin/postadmin.php)

namespace dn\sitebundle\admin;  use sonata\adminbundle\admin\admin; use sonata\adminbundle\form\formmapper; use sonata\adminbundle\datagrid\datagridmapper; use sonata\adminbundle\datagrid\listmapper; use sonata\adminbundle\show\showmapper; use sonata\corebundle\validator\errorelement; use knp\menu\iteminterface menuiteminterface;  class postadmin extends admin {  // fields shown on create/edit forms protected function configureformfields(formmapper $formmapper) {     $formmapper         ->add('title', 'text', array('label' => 'post title'))         ->add('content')  ->add('publication') ->add('author')     ->add('collection', 'sonata_type_model_list', array('required' =>  false));  } //... } ?> 

this code in post.php (src/dn/sitebundle/entity/post.php)

 namespace dn\sitebundle\entity;      use doctrine\orm\mapping orm;     use gedmo\mapping\annotation gedmo;     use doctrineextensions\taggable\taggable;     use doctrine\common\collections\arraycollection;       /**      * @orm\entity      */     class post implements taggable     {     /**      * @var integer      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @orm\column(name="title", type="string", length=255)      */     private $title;      /**      * @var string      *      * @orm\column(name="author", type="string", length=255)      */     private $author;      /**      * @var string      *      * @orm\column(name="content", type="text")      */     private $content;      /**      * @var \datetime      *      * @orm\column(name="created_at", type="datetime")      */     private $created_at;      /**      * @var boolean      *      * @orm\column(name="publication", type="boolean")      */     private $publication;      /**      * @var string         * @gedmo\slug(fields={"title"})      * @orm\column(name="slug", type="string", length=255)      */      private $slug;        private $tags;        public function gettags()     {         $this->tags = $this->tags ?: new arraycollection();          return $this->tags;     }      public function gettaggabletype()     {         return 'dn_tag';     }      public function gettaggableid()     {         return $this->getid();     }         /**      * id      *      * @return integer       */     public function getid()     {         return $this->id;     }      /**      * set title      *      * @param string $title      * @return post      */     public function settitle($title)     {         $this->title = $title;          return $this;     }      /**      * title      *      * @return string       */     public function gettitle()     {         return $this->title;     }      /**      * set author      *      * @param string $author      * @return post      */     public function setauthor($author)     {         $this->author = $author;          return $this;     }      /**      * author      *      * @return string       */     public function getauthor()     {         return $this->author;     }      /**      * set content      *      * @param string $content      * @return post      */     public function setcontent($content)     {         $this->content = $content;          return $this;     }      /**      * content      *      * @return string       */     public function getcontent()     {         return $this->content;     }        /**      * set publication      *      * @param boolean $publication      * @return post      */     public function setpublication($publication)     {         $this->publication = $publication;          return $this;     }      /**      * publication      *      * @return boolean       */     public function getpublication()     {         return $this->publication;     }      /**      * set slug      *      * @param string $slug      * @return post      */     public function setslug($slug)     {         $this->slug = $slug;          return $this;     }      /**      * slug      *      * @return string       */     public function getslug()     {         return $this->slug;     }         /**      * set created_at      *      * @param \datetime $createdat      * @return post      */     public function setcreatedat($createdat)     {         $this->created_at = $createdat;          return $this;     }      /**      * created_at      *      * @return \datetime       */     public function getcreatedat()     {         return $this->created_at;     }              public function __construct()     {         $this->created_at = new \datetime("now");     }      public function __tostring()     {         return $this->gettitle();     }     } 

the name of field should "tags" instead of "collection" guess.

i don't see property "collection" in entity.

the first parameter of add method should name of property defined in entity.

namespace dn\sitebundle\admin;  use sonata\adminbundle\admin\admin; use sonata\adminbundle\form\formmapper; use sonata\adminbundle\datagrid\datagridmapper; use sonata\adminbundle\datagrid\listmapper; use sonata\adminbundle\show\showmapper; use sonata\corebundle\validator\errorelement; use knp\menu\iteminterface menuiteminterface;  class postadmin extends admin {     // fields shown on create/edit forms     protected function configureformfields(formmapper $formmapper)     {         $formmapper             ->add('title', 'text', array('label' => 'post title'))             ->add('content')             ->add('publication')             ->add('author')             ->add('collection', 'sonata_type_model_list', array('required' =>  false));     } //... } ?> 

documentation on forms : https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/form_field_definition.html


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -