Sylius: How to create new entity using Timestampable and Slugable

Created on 30 Aug 2016  路  8Comments  路  Source: Sylius/Sylius

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;
Help Wanted

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

All 8 comments

@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

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chrysweel picture Chrysweel  路  3Comments

loic425 picture loic425  路  3Comments

hmonglee picture hmonglee  路  3Comments

reyostallenberg picture reyostallenberg  路  3Comments

mikemix picture mikemix  路  3Comments