I'm trying to create a few entities with the new Sylius version (1.0).
I'm reading their docs but i'm getting a bit mad.
Got a new Entity Book.php.
This entity got three fields, author, title and content.
How can I use the Slugable and Timestampable on this entity to create two new fields on this entity using annotations?
Book.php
<?php
namespace Acme\SyliusBookBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Model\ResourceInterface;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Book
*
* @ORM\Table(name="book")
* @ORM\Entity(repositoryClass="App\SyliusBookBundle\Repository\BookRepository")
*/
class Book implements ResourceInterface
{
public function __construct()
{
$this->createdAt = new \DateTime();
}
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="Sylius\Component\User\Model\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $author;
/**
* @var string
*
* @ORM\Column(name="content", type="text")
*/
private $content;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
@bnd170 Just like with any other Symfony entity. Use Doctrine GedmoExtensions and we even have ready to use traits if you want.
@pjedrzejewski can you leave an example? Seems a good idea to add on documentation :)
BTW Amazing work with Sylius, you got a new lover :D
So future discussion see - http://stackoverflow.com/questions/39230882/sylius-implements-slugable-and-timestampable-in-new-entity
@pjedrzejewski any help? The question is: Anyway to configure createdAt and updatedAt with annotations using traits?
Its ok, i found it. Using use Gedmo\Timestampable\Traits\TimestampableEntity; it works.
Can u close this :) Thanks a lot for help.
@bnd170 As an author you should also be able to close an issue.
Right, i'm a bit new on github participant. Thanks @lchrusciel.
@bnd170 thanks :) Also, I have left you some explanation on stackoverflow, why don't we use an annotation.
Most helpful comment
@pjedrzejewski can you leave an example? Seems a good idea to add on documentation :)
BTW Amazing work with Sylius, you got a new lover :D