php - Doctrine OneByOne's and Date -


i using symfony 2.7.1 , seem have problem while using news entity. trying use published_at in twig template.

i tried using {{ news_item.published_at|date("m/d/y") }} seems follow fatal error:

method "published_at" object "appbundle\entity\news" not exist in appbundle:news:index.html.twig @ line 7 

line 7:

{{ news_item.published_at | date("m/d/y") }} 

i 'invalid entities' warning in debug toolbar stating following;

  • appbundle\entity\account
    • the association appbundle\entity\account#articles refers owning side field appbundle\entity\news#author not defined association, field.
    • the association appbundle\entity\account#articles refers owning side field appbundle\entity\news#author not exist.

these files. hope can me push me in right direction:

src/appbundle/entity/news.php

class news {     /**      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @orm\column(name="title", type="string", length=255)      */     private $title;      /**      * @orm\column(name="body", type="text")      */     private $body;      /**      * @orm\column(name="author", type="integer")      * @orm\manytoone(targetentity="appbundle\entity\account", inversedby="articles")      */     private $author;      /**      * @orm\column(name="published_at", type="datetime")      */     private $published_at; } 

src/appbundle/entity/repositories/newsrepository.php

class newsrepository extends entityrepository {     /**      * @param $number      * @return mixed      * @throws \doctrine\orm\nonuniqueresultexception      */     public function findlatest($number) {         return $this->createquerybuilder('a')             ->orderby('a.published_at', 'desc')             ->setmaxresults($number)             ->getquery()             ->getresult();     } } 

src/appbundle/entity/account.php

class account implements advanceduserinterface {     /**      * @orm\onetomany(targetentity="appbundle\entity\news", mappedby="author")      */     protected $articles; } 

your entity class needs getters (and setter).

class news {     // ...      /**      * @orm\column(name="published_at", type="datetime")      */     private $published_at;      public function getpublished_at()     {         return $this->published_at;     } } 

with {{ news_item.published_at }} will call news::getpublished_at.

(...) if not, , if foo object, check getbar valid method; (...)

you can directly method in twig {{ news_item.getpublished_at() }}


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -