I am following Udemy course:
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\ModelBundl e\Entity\Post:: $createdAt".
(I comment out "createdAt" in template and than Author, title and post are displayed. )
_post.html.twig :
C:\Bitnami\wamp stack-5.4.38-0\sym_prog\mypr oject\src\Blog\ ModelBundle\Ent ity\Post.php
C:\Bitnami\wamp stack-5.4.38-0\sym_prog\mypr oject\src\Blog\ ModelBundle\Ent ity\Timestampab le.php
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\ModelBundl e\Entity\Post:: $createdAt".
(I comment out "createdAt" in template and than Author, title and post are displayed. )
_post.html.twig :
Code:
<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>
Code:
...
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\wamp stack-5.4.38-0\sym_prog\mypr oject\src\Blog\ ModelBundle\Ent ity\Timestampab le.php
Code:
.... abstract class Timestampable
{
/**
*
* @var \DateTime
* @ORM\Column (name="created_at", type="datetime")
*/
private $createdAt;
/**
* Construct
*/
public function __construct()
{
$this->createdAt = new \DateTime();
}....