symfony - Mapping doesn't work ORM -


i have example:

log.php

    <?php // src/mailing/mailingbundle/entity/log.php  namespace mailing\mailingbundle\entity;  use doctrine\orm\mapping orm;  /**  * @orm\entity  * @orm\table(name="log") */  class log {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     protected $id;       /**      * @orm\column(type="string", length=20)      */     protected $action;      public function getaction() {         return $this->action;     }      public function setaction($action) {         $this->action = $action;     }      /**      * @orm\column(type="datetime")      */     protected $date;      public function getdate() {         return $this->date;     }      public function setdate($date) {         $this->date = $date;     }      /**      * @orm\column(type="integer", name="mail_id")      * @orm\onetoone(targetentity="mail")      */     protected $mail;      public function getmail() {         return $this->mail;     }      public function setmail($mail) {         $this->mail = $mail;     }      /**      * @orm\column(type="integer", name="template_id")      * @orm\onetoone(targetentity="template")      */     protected $template;      public function gettemplate() {         return $this->template;     }      public function settemplate($template) {         $this->template = $template;     } } 

mail.php

<?php // src/mailing/mailingbundle/entity/mail.php  namespace mailing\mailingbundle\entity;  use doctrine\orm\mapping orm;  /**  * @orm\entity  * @orm\table(name="mail") */  class mail {     /**      * @orm\id      * @orm\column(type="integer")      * @orm\generatedvalue(strategy="auto")      */     protected $id;      public function getid() {         return $this->id;     }      /**      * @orm\column(type="string", length=200)      */     protected $address;      /**      *       * @return type      */     public function getaddress() {         return $this->address;     }      /**      *       * @param \mailing\mailingbundle\entity\mail $surname      */     public function setaddress($address)     {         $this->address = $address;     }      /**      * @orm\column(type="string", length=200)      */     protected $name;      /**      *       * @return type      */     public function getname() {         return $this->name;     }      /**      *       * @param \mailing\mailingbundle\entity\mail $surname      */     public function setname($name)     {         $this->name = $name;     }      /**      * @orm\column(type="string", length=200)      */     protected $surname;      /**      *       * @return type      */     public function getsurname() {         return $this->surname;     }      /**      *       * @param \mailing\mailingbundle\entity\mail $surname      */     public function setsurname($surname)     {         $this->surname = $surname;     }      /**      * @orm\column(type="boolean")      */     protected $subscribed;      /**      *       * @return type      */     public function getsubscribed() {         return $this->subscribed;     }      /**      *       * @param \mailing\mailingbundle\entity\mail $subscribed      */     public function setsubscribed($subscribed)     {         $this->subscribed = $subscribed;     }       /**      * @orm\manytomany(targetentity="inventory", inversedby="articles")      * @orm\jointable(      *     name="mail_inventory",      *     joincolumns={      *         @orm\joincolumn(name="mail_id", referencedcolumnname="id")      *     },      *     inversejoincolumns={      *         @orm\joincolumn(name="iventory_id", referencedcolumnname="id")      *     }      * )      */     protected $inventories;      /**      * @return doctrinecommoncollectionscollection;      */     public function getinventories()     {         return $this->inventories;     }      /**      * @orm\column(type="string", length=128)      */     protected $hash;      public function gethash() {         return $this->hash;     }      public function sethash($hash) {         $this->hash = $hash;     }  } 

logcontroller.php

<?php // src/mailing/mailingbundle/controller/logcontroller.php  namespace mailing\mailingbundle\controller;  use symfony\bundle\frameworkbundle\controller\controller;  class logcontroller extends controller {     public function indexaction()     {         $em = $this->getdoctrine()->getmanager();         $records = $em->getrepository('mailingbundle:log')->findall();                 return $this->render('mailingbundle:log:index.html.twig', array('logs' =>$records));     } } 

template:

{# src/mailing/mailingbundle/resources/views/log/index.html.twig #} {% extends 'mailingbundle::layout.html.twig' %}  {% block title %}     log {% endblock %}  {% block headline %}     log {% endblock %}  {% block content %}     {% if logs %}     <table>         <tr><th>date</th><th>e-mail</th><th>template</th></tr>         {% log in logs %}                 <tr><td>{{ log.date|date('h:i j.n.y') }}</td><td>{{ log.action }}</td><td>{{ log.mail.address }}</td><td>{{ log.template.name }}</td></tr>         {% endfor %}     </table>     {% else %}         no records show...     {% endif %} {% endblock %} 

it generates error:

impossible access attribute ("address") on integer variable ("1") in mailingbundle:log:index.html.twig @ line 17

this db schema

log id  int(11) no  pri null    auto_increment action  varchar(20) yes     null     date    datetime    yes     null     mail_id int(11) no  mul null     template_id int(11) yes mul null  mail field   type    null    key     default        id  int(11) no  pri null    auto_increment address varchar(200)    no      null     name    varchar(200)    yes     null     surname varchar(200)    yes     null     subscribed  tinyint(1)  yes     1    hash    varchar(128)    no      null 

thank help.

according documentation: doctrine doc

you wrong declare record:

/**  * @orm\column(type="integer", name="mail_id")  * @orm\onetoone(targetentity="mail")  */ protected $mail; 

instead must be:

/**  * @onetoone(targetentity="mail")  * @joincolumn(name="mail_id", referencedcolumnname="id")  */  protected $mail; 

the same thing $template.

edit:

if can not make work can try bidirectional association: onetoone bidirectional

log.php

/**  * @onetoone(targetentity="mail", inversedby="log")  * @joincolumn(name="mail_id", referencedcolumnname="id")  */  protected $mail; 

mail.php

/**  * @onetoone(targetentity="log", mappedby="mail")  **/ private $log; 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -