Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Fixtures


After creating the database structure, it would be handy to prepare some test data. We can do this through fixtures. Unfortunately, Symfony2 does not come with any fixtures system, so we need to install it. Type the following:

$ php composer.phar require doctrine/doctrine-fixtures-bundle

Now register the bundle in app/AppKernel.php:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
        // […]
        if (in_array(/* […] */, array('dev', 'test'))) {
            // …
        $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
}

If everything goes well, you should see new options when you type the following:

$ php app/console

This should give you a new command called doctrine:fixtures:load.

Now let's create a simple fixture class to load an example tag.

In the src/AppBundle/DataFixtures/ORM directory, create a file called LoadTagData.php:

<?php

namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures...