doctrine2 - zf2 doctrine 2 - Output OnetoOne Unidirectional -


after annotating onetoone unidirectional, want output joined column, without using form.

one people entity has got column store id of country entity.

what can do: can store id of country people entity using form dropdown select, bound country entity.

problem: can not enter value country of the, correct, joined table.

people entity:

<?php  namespace people\entity;  use doctrine\orm\mapping orm; // ...  /** * people entity. * * @orm\entity * @orm\table(name="icd_people") * @property int $id // ... * @property string $ic_hq_country */ class people implements inputfilterawareinterface { protected $inputfilter;  /** * @orm\id * @orm\column(type="integer"); */ protected $id;  /** * @orm\column(type="integer") * @orm\onetoone(targetentity="country") * @orm\joincolumn(name="ic_hq_country", referencedcolumnname="id") */ protected $ic_hq_country;  // getter , setter } 

the country entity:

<?php  namespace people\entity;  use doctrine\orm\mapping orm; //...  /** * country entity. * * @orm\entity * @orm\table(name="pre_country") * @property int $id * @property string $country */ class country implements inputfilterawareinterface { protected $inputfilter;   /**  * @orm\id  * @orm\column(type="integer");  */ protected $id;  /** * @orm\column(type="string") */ protected $country;  /**  * id  *  * @return integer  */ public function getid() {     return $this->id; }  /**  * set country  *  * @param string $country  * @return country  */ public function setcountry($country) {     $this->country = $country;      return $this; }  /**  * country  *  * @return string  */ public function getcountry() {     return $this->country; }  /** * convert object array. * * @return array */ public function getarraycopy() {     return get_object_vars($this); }  public function setinputfilter(inputfilterinterface $inputfilter) {     throw new \exception("not used"); }  public function getinputfilter() {     throw new \exception("not used"); } } 

the controller action:

public function indexaction() {      $userid =  $this->zfcuserauthentication()->getidentity()->getid();       return new viewmodel(array(         'pea' => $this->getentitymanager()->find('people\entity\people', $userid), )); } 

the view giving id of country, not name:

<?php echo $this->escapehtml($pea->ic_hq_country);?>

i expected being possible, output country name , not id:

<?php echo $this->escapehtml($pea->country);?>

thank reading, , help, lead me right direction!

you should not use @column anotation in $ic_hq_country field of peopleentity.

/** * @orm\onetoone(targetentity="country") * @orm\joincolumn(name="ic_hq_country", referencedcolumnname="id") */ protected $ic_hq_country; 

like this, ic_hq_country proxy entity instead of id.

so in view can use:

<?php echo $pea->ic_hq_country->getid();?> 

and

<?php echo $this->escapehtml($pea->ic_hq_country->getcountry());?> 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -