Skip to content

Latest commit

 

History

History
65 lines (47 loc) · 1.33 KB

doctrine_extensions.md

File metadata and controls

65 lines (47 loc) · 1.33 KB

Doctrine Extensions

StofDoctrineExtensionsBundle is a layer around another library called DoctrineExtensions, which can add some features to our entities.

composer require stof/doctrine-extensions-bundle

To activate desired feature edit config/packages/stof_doctrine_extensions.yaml:

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            sluggable: true
            timestampable: true

Sluggable

It urlizes your specified fields into single unique slug.

Let's apply @Gedmo\Slug annotation to the field where we want store slug.

Edit src/Entity/Question.php:

use Gedmo\Mapping\Annotation as Gedmo;

class Question
{
    /**
     * @ORM\Column(type="string", length=100, unique=true)
     * @Gedmo\Slug(fields={"name"})
     */
    private $slug;
    
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;
}

Timestampable

Updates date fields on create, update and even property change.

Edit src/Entity/Question.php:

use Gedmo\Timestampable\Traits\TimestampableEntity;

class Question
{
    use TimestampableEntity;
}

Loggable

It helps tracking changes and history of objects, also supports version management.