symfony - how to access annotation of an property(class,mappedBy,inversedBy) -


good morning,

is exist function pass entity , propertyname , return me mappedby,inversedby , absoluteclassname of entity. goal use __call create automatic getteur/setteur , addfucntion bidirectionnal. don't want use generates entities want getteur,setteur , add function use __call. can"t addbirectionnal if don't know if relation many many or 1 many , if don't know name of mappedby.

my code:

 public function __get($p){         return $this->$p;     }     public function __set($p,$v){         $this->$p = $v;         return $this;     }       public function __call($name,$arguments){         if(substr($name,1,3)=='et')             $name2 = substr(3);             if($name[0] == 'g'){                 return $this->$name2;             }else{//substr($name,0,1) == 's'                 $this->$name2 = $arguments[0];                 /*for 1 one*/                 /*$mappedbyname= getmappedbyorinversedby(get_class($name),$name2);                 if($mappedbyname){                      $this->$name->$mappedbyname = $this;/                 }*/                 return $this;             }         }     } 

i need getmappedbyorinversedby, thanks.

edit: try this

 public function test(){         $str = "appbundle\entity\group";         $mapping = new \doctrine\orm\mapping\classmetadatainfo($str);         $d = $mapping->getassociationmappedbytargetfield('trad');         var_dump($d);          return $this->render('default/index.html.twig', array(             'base_dir' => realpath($this->getparameter('kernel.root_dir').'/..'),         ));     }   class group {      ...      /**     * @orm\onetoone(targetentity="traduction",inversedby="grp")     */     protected $trad; } 

result : undefined index: trad

the classmetadatainfo looking for.

creates instance entityname :

$mapping = new \doctrine\orm\mapping\classmetadatainfo($entitynamespaceoralias);  

then, informations want :

get association names: $mapping->getassociationnames();

get join column of association:
$mapping->getsingleassociationjoincolumnname($fieldname);

get mappedby column of association:
$mapping->getassociationmappedbytargetfield($fieldname);

...

look @ class know method can access.
hopes it's expect.

edit

as can access entitymanager (i.e. controller), use :

$em = $this->getdoctrine()->getmanager(); $metadata = $em->getclassmetadata('appbundle:group'); 

to sure there no problem entity namespace, try :

print $metadata->gettablename(); 

to retrieve associations of entity, use :

$metadata->getassociationnames(); 

and mapping informations of existing association, use :

$metadata->getassociationmapping($fieldname); 

and association mappings of entity, use:

$metadata->getassociationmappings(); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -