I am using Symfony 2.7.1 and I seem to have a problem while using my News Entity. I am trying to use the published_at in my twig template.
I tried using {{ news_item.published_at|date("m/d/Y") }}
but that seems to follow up by a fatal error:
Method "published_at" for object "AppBundle\Entity\News" does not exist in AppBundle:news:index.html.twig at line 7
Line 7:
{{ news_item.published_at | date("m/d/Y") }}
I also get a 'Invalid entities' warning in the debug toolbar stating the following;
- AppBundle\Entity\Account
- The association AppBundle\Entity\Account#articles refers to the owning side field AppBundle\Entity\News#author which is not defined as association, but as field.
- The association AppBundle\Entity\Account#articles refers to the owning side field AppBundle\Entity\News#author which does not exist.
These are my files. I hope somebody can help me push me in the 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;
}