Tuesday, 15 February 2011

symfony2 - Property "groups" is not public in class "Backend\UsuariosBundle\Entity\Usuario". Maybe you should create the method "setGroups()"? -



symfony2 - Property "groups" is not public in class "Backend\UsuariosBundle\Entity\Usuario". Maybe you should create the method "setGroups()"? -

i have problem , can´t resolve it. i'm newbie in symfony 2. explain problem. have usuario class , grouping class. have overwritten registrationform add together grouping users.

this code

<?php namespace backend\usuariosbundle\form\type; utilize symfony\component\form\formbuilderinterface; utilize fos\userbundle\form\type\registrationformtype basetype; class registrationformtype extends basetype { public function buildform(formbuilderinterface $builder, array $options) { // agrega tu campo personalizado $builder->add('name', 'text', array('label'=>'nombre completo de usuario:')); parent::buildform($builder, $options); // agrega tu campo personalizado $builder->add('roles', 'choice', array('label' => 'elige united nations rol para el usuario', 'required' => true, 'choices' => array( 1 => 'role_admin', 2 => 'role_user'), 'multiple' => true)) ->add('groups', 'entity', array( 'label' => 'asociar al grupo de', 'empty_value' => 'elija united nations grupo para el usuario', 'class' => 'backendusuariosbundle:group', 'property' => 'name', )) ; } public function getname() { homecoming 'mi_user_registration'; } }

and usuario class this:

<?php namespace backend\usuariosbundle\entity; utilize fos\userbundle\entity\user baseuser; utilize doctrine\orm\mapping orm; utilize symfony\component\validator\constraints assert; utilize symfony\bridge\doctrine\validator\constraints\uniqueentity; utilize \fos\userbundle\model\groupinterface; utilize doctrine\common\collections\arraycollection; /** * @orm\entity * @orm\table(name="usuario") * @uniqueentity(fields="username") * @uniqueentity(fields="email") */ class usuario extends baseuser { /** * @orm\column(type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @orm\column(type="string", length=50) * * @assert\notblank(message="por favor, introduce tu nombre.", groups={"registration", "profile"}) * @assert\minlength(limit="3", message="el nombre es demasiado corto.", groups={"registration", "profile"}) * @assert\maxlength(limit="50", message="el nombre es demasidado largo.", groups={"registration", "profile"}) */ protected $name; /** * @orm\manytomany(targetentity="backend\usuariosbundle\entity\group") * @orm\jointable(name="fos_user_user_group", * joincolumns={@orm\joincolumn(name="user_id", referencedcolumnname="id")}, * inversejoincolumns={@orm\joincolumn(name="group_id", referencedcolumnname="id")} * ) */ protected $groups; public function __construct() { $this->groups = new arraycollection(); parent::__construct(); } /** * set name * * @param string $name * @return usuario */ public function setname($name) { $this->name = $name; homecoming $this; } /** * name * * @return string */ public function getname() { homecoming $this->name; } /** * agrega united nations rol al usuario. * @throws exception * @param rol $rol */ public function addrole( $rol ) { $this->roles = array(); if($rol == 1) { array_push($this->roles, 'role_admin'); } else if($rol == 2) { array_push($this->roles, 'role_user'); } } /** * id * * @return integer */ public function getid() { homecoming $this->id; } /** * add together groups * * @param \fos\userbundle\entity\group $groups * @return usuario */ public function addgroup(groupinterface $groups) { $this->groups[] = $groups; homecoming $this; } /** * remove groups * * @param \fos\userbundle\model\groupableinterface $groups */ public function removegroup(groupinterface $groups) { $this->groups->removeelement($groups); } /** * groups * * @return \doctrine\common\collections\collection */ public function getgroups() { homecoming $this->groups; } }

form shows correctly @ save show me error: property "groups" not public in class "backend\usuariosbundle\entity\usuario". maybe should create method "setgroups()"?

why? help/ideas?

thanks help.

i suppose inexperience extend php , programming in general. however, we're here help you.

as error says (is lucky case when error speaking) you're missing method called setgroups()

you should implement it, in next way

/** * set groups * * @param doctrine\common\collections\arraycollection $groups * @return usuario */ public function setgroups(arraycollection $groups) { $this->groups = $groups; homecoming $this; }

this method different existing method of class, called addgroup; addgroup extend existing array of groups, whereas setgroups() set groups arraycollection and, if other groups associated, overwritten.

symfony2 form engine work, default, setxxxx (where xxxx property you're going add) methods vital implement them.

symfony2 fosuserbundle

No comments:

Post a Comment