symfony2 - Sonata and Gedmo\References doctrine extension doesn't work ( Class does not exist ) -
i want link doctrine orm entity , doctrine odm document , utilize them in sonataadminbundle in configureformfields method of admin class.
i've established @gedmo\references doctrine-extension , works fine when i'm trying access linked models controller.
but need sonataadminbundle - create ui add together linked documents user entity.
here entity:
<?php namespace application\sonata\userbundle\entity; utilize doctrine\orm\mapping orm; utilize sonata\userbundle\entity\baseuser; utilize fos\userbundle\model\groupinterface; utilize sonata\userbundle\model\userinterface; utilize gedmo\mapping\annotation gedmo; utilize application\sonata\userbundle\document\address; class user extends baseuser { /** * @var integer */ protected $id; /** * @var string */ private $phone2; /** * @var string */ private $phone3; /** * @var string */ private $photo; /** * @var string */ private $addressbook; /** * @var integer */ private $dval; /** * @var integer */ private $dvalman; /** * @var arraycollection * @gedmo\referencemany(type="document", class="\application\sonata\userbundle\document\address", mappedby="user") */ protected $addresses; /** * constructor */ public function __construct() { parent::__construct(); $this->groups = new \doctrine\common\collections\arraycollection(); $this->addresses = new \doctrine\common\collections\arraycollection(); } /** * id * * @return integer */ public function getid() { homecoming $this->id; } /** * @var \doctrine\common\collections\collection */ protected $groups; public function setphone($phone) { $this->phone = $phone; $this->usernamecanonical = $phone; $this->username = $phone; } /** * set phone2 * * @param string $phone2 * @return user */ public function setphone2($phone2) { $this->phone2 = $phone2; homecoming $this; } /** * phone2 * * @return string */ public function getphone2() { homecoming $this->phone2; } /** * set phone3 * * @param string $phone3 * @return user */ public function setphone3($phone3) { $this->phone3 = $phone3; homecoming $this; } /** * phone3 * * @return string */ public function getphone3() { homecoming $this->phone3; } /** * set photo * * @param string $photo * @return user */ public function setphoto($photo) { $this->photo = $photo; homecoming $this; } /** * photo * * @return string */ public function getphoto() { homecoming $this->photo; } /** * set addressbook * * @param string $addressbook * @return user */ public function setaddressbook($addressbook) { $this->addressbook = $addressbook; homecoming $this; } /** * addressbook * * @return string */ public function getaddressbook() { homecoming $this->addressbook; } /** * set dval * * @param integer $dval * @return user */ public function setdval($dval) { $this->dval = $dval; homecoming $this; } /** * dval * * @return integer */ public function getdval() { homecoming $this->dval; } /** * set dvalman * * @param integer $dvalman * @return user */ public function setdvalman($dvalman) { $this->dvalman = $dvalman; homecoming $this; } /** * dvalman * * @return integer */ public function getdvalman() { homecoming $this->dvalman; } /** * gets groups granted user. * * @return collection */ public function getgroups() { homecoming $this->groups ?: $this->groups = new arraycollection(); } public function getgroupnames() { $names = array(); foreach ($this->getgroups() $group) { $names[] = $group->getname(); } homecoming $names; } public function hasgroup($name) { homecoming in_array($name, $this->getgroupnames()); } public function addgroup(groupinterface $group) { if (!$this->getgroups()->contains($group)) { $this->getgroups()->add($group); } homecoming $this; } public function removegroup(groupinterface $group) { if ($this->getgroups()->contains($group)) { $this->getgroups()->removeelement($group); } homecoming $this; } /** * returns gender list * * @return array */ public static function getgenderlist() { homecoming array( userinterface::gender_unknown => 'Неизвестно', userinterface::gender_male => 'Мужской', userinterface::gender_female => 'Женский', ); } /** * @var \doctrine\common\collections\collection */ private $children; /** * @var \application\sonata\userbundle\entity\user */ private $parent; /** * add together children * * @param \application\sonata\userbundle\entity\user $children * @return user */ public function addchild(\application\sonata\userbundle\entity\user $children) { $this->children[] = $children; homecoming $this; } /** * remove children * * @param \application\sonata\userbundle\entity\user $children */ public function removechild(\application\sonata\userbundle\entity\user $children) { $this->children->removeelement($children); } /** * children * * @return \doctrine\common\collections\collection */ public function getchildren() { homecoming $this->children; } /** * set parent * * @param \application\sonata\userbundle\entity\user $parent * @return user */ public function setparent(\application\sonata\userbundle\entity\user $parent = null) { $this->parent = $parent; homecoming $this; } /** * parent * * @return \application\sonata\userbundle\entity\user */ public function getparent() { homecoming $this->parent; } public function setaddresses(\doctrine\common\collections\arraycollection $addresses) { $this->addresses = $addresses; } public function getaddresses() { homecoming $this->addresses; } } and document:
<?php namespace application\sonata\userbundle\document; utilize doctrine\common\collections\collection; utilize gedmo\mapping\annotation gedmo; utilize application\sonata\userbundle\entity\user; class address { /** * @var mongoid $id */ protected $id; /** * @var string $firstname */ protected $firstname; /** * @var string $lastname */ protected $lastname; /** * @var string $address */ protected $address; /** * @var string $postcode */ protected $postcode; /** * @var string $phone */ protected $phone; /** * @var string $comment */ protected $comment; /** * @gedmo\referenceone(type="entity", class="\application\sonata\userbundle\entity\user", inversedby="addresses", identifier="user_id", mappedby="user_id") */ protected $user; /** * @var int $user_id */ protected $user_id; /** * @var int $delivery_id */ protected $delivery_id; /** * @var int $city_id */ protected $city_id; /** * id * * @return id $id */ public function getid() { homecoming $this->id; } /** * set firstname * * @param string $firstname * @return self */ public function setfirstname($firstname) { $this->firstname = $firstname; homecoming $this; } /** * firstname * * @return string $firstname */ public function getfirstname() { homecoming $this->firstname; } /** * set lastname * * @param string $lastname * @return self */ public function setlastname($lastname) { $this->lastname = $lastname; homecoming $this; } /** * lastname * * @return string $lastname */ public function getlastname() { homecoming $this->lastname; } /** * set address * * @param string $address * @return self */ public function setaddress($address) { $this->address = $address; homecoming $this; } /** * address * * @return string $address */ public function getaddress() { homecoming $this->address; } /** * set postcode * * @param string $postcode * @return self */ public function setpostcode($postcode) { $this->postcode = $postcode; homecoming $this; } /** * postcode * * @return string $postcode */ public function getpostcode() { homecoming $this->postcode; } /** * set phone * * @param string $phone * @return self */ public function setphone($phone) { $this->phone = $phone; homecoming $this; } /** * phone * * @return string $phone */ public function getphone() { homecoming $this->phone; } /** * set comment * * @param string $comment * @return self */ public function setcomment($comment) { $this->comment = $comment; homecoming $this; } /** * comment * * @return string $comment */ public function getcomment() { homecoming $this->comment; } /** * set userid * * @param int $userid * @return self */ public function setuserid($userid) { $this->user_id = $userid; homecoming $this; } /** * userid * * @return int $userid */ public function getuserid() { homecoming $this->user_id; } /** * set deliveryid * * @param int $deliveryid * @return self */ public function setdeliveryid($deliveryid) { $this->delivery_id = $deliveryid; homecoming $this; } /** * deliveryid * * @return int $deliveryid */ public function getdeliveryid() { homecoming $this->delivery_id; } /** * set cityid * * @param int $cityid * @return self */ public function setcityid($cityid) { $this->city_id = $cityid; homecoming $this; } /** * cityid * * @return int $cityid */ public function getcityid() { homecoming $this->city_id; } } here configureformfields method:
protected function configureformfields(formmapper $formmapper) { $formmapper ->with('general') ->add('addresses', 'sonata_type_model', array( 'required' => false, 'expanded' => true, 'multiple' => true )) ->end(); } it says: class not exist
i tried sonata_type_collection too, it's error too:
->add('addresses', 'sonata_type_collection', array( // prevents "delete" alternative beingness displayed 'type_options' => array('delete' => false) ), array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'position', )) the current field addresses not linked admin. please create 1 target entity : ``
what sonata_form_type should utilize create work???
i ran same issue @arferr. solution utilize 'entity' type , add together related class name form field:
protected function configureformfields(formmapper $formmapper) { $formmapper // ->add('branch', 'sonata_type_model', array( // unknown document namespace alias 'plusquamcontractbundle'. ->add('branch', 'entity', array( 'class' => 'plusquamcontractbundle:branch', 'by_reference' => false )) ; } this create "class not exist" error disappear.
symfony2 reference doctrine2 sonata-admin doctrine-extensions
No comments:
Post a Comment