https://www.udemy.com/introduction-to-web-development-with-symfony2/#/lecture/933836
There is Post model with several fields: title, author, body;
which inherits from Timestampable model with field: createdAt.
When i try to display Post model in template, the Author and post are displayed, but field "createdAt" is not recognised and gives error "Notice: Undefined property: Blog\ModelBundle\Entity\Post::$createdAt".
(I comment out "createdAt" in template and than Author, title and post are displayed. )
_post.html.twig:
Expand|Select|Wrap|Line Numbers
- <article>
- <header><h2><a href="a">{{post.title}}</a></h2> </header>
- <p>{{'post.on' | trans }}
- <time datetime="{{ post.createdAt | date('c') }}">{{ post.createdAt | date }} </time>
- {{ 'by' | trans }} <a href="a"> {{ post.author.name }} </a>
- </p>
- </header>
- <p> {{post.body |truncate(400)}} — <a href=""a">{{ 'read.more' | trans }} »</a></p>
- </article>
Expand|Select|Wrap|Line Numbers
- ...
- class Post extends Timestampable
- {
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string
- *
- * @ORM\Column(name="title", type="string", length=150)
- * @Assert\NotBlank
- */
- private $title;
- /**
- * @var string
- *
- * @ORM\Column(name="body", type="text")
- * @Assert\NotBlank
- */
- private $body;
- /**
- * @var Author
- *
- * @ORM\ManyToOne(targetEntity="Author", inversedBy="posts")
- * @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false)
- * @Assert\NotBlank
- */
- private $author;
- ...
C:\Bitnami\wampstack-5.4.38-0\sym_prog\myproject\src\Blog\ModelBundle\Entity\T imestampable.php
Expand|Select|Wrap|Line Numbers
- .... abstract class Timestampable
- {
- /**
- *
- * @var \DateTime
- * @ORM\Column (name="created_at", type="datetime")
- */
- private $createdAt;
- /**
- * Construct
- */
- public function __construct()
- {
- $this->createdAt = new \DateTime();
- }....