Fixtures are data you usually write to populate your database during the development, or static content like menus, labels, ... you need by default in your database in production.
The following command is designed to load fixtures:
> php app/console propel:fixtures:load [-d|--dir[="..."]] [--xml] [--sql] [--yml] [--connection[="..."]] [bundle]
As you can see, there are many options to allow you to easily load fixtures.
--connection allows to specify a connection. The
--dir option allows to specify a directory
containing the fixtures (default is:
Note that the
--dir expects a relative path from the root dir (which is
--xml parameter allows you to load only XML fixtures.
--sql parameter allows you to load only SQL fixtures.
--yml parameter allows you to load only YAML fixtures.
You can mix
--sql parameters to load XML, YAML and SQL fixtures at the same time.
If none of this parameter are set all files YAML, XML and SQL in the directory will be load.
You can pass a bundle name to load fixtures from it. A bundle's name starts with
> php app/console propel:fixtures:load @AcmeDemoBundle
A valid XML fixtures file is:
<Fixtures> <Object Namespace="Awesome"> <o1 Title="My title" MyFoo="bar" /> </Object> <Related Namespace="Awesome"> <r1 ObjectId="o1" Description="Hello world !" /> </Related> </Fixtures>
A valid YAML fixtures file is:
Awesome\Object: o1: Title: My title MyFoo: bar Awesome\Related: r1: ObjectId: o1 Description: Hello world ! Awesome\Tag: t1: name: Foo t2: name: Baz Awesome\Post: p1: title: A Post with tags (N-N relation) tags: [ t1, t2 ]
Using Faker in YAML Fixtures
Acme\DemoBundle\Model\Book: Book1: name: "Awesome Feature" description: <?php $faker('text', 500); ?>
The aim of this feature is to be able to mix real, and fake data in the same file. Fake data are interesting to quickly add data tou your application, but most of the time you need to rely on real data. To integrate Faker in the YAML files allows to write strong fixtures efficiently.
You can dump data from your database into YAML fixtures file by using this command:
> php app/console propel:fixtures:dump [--connection[="..."]]
Dumped files will be written in the fixtures directory:
app/propel/fixtures/ with the following name:
99999 is a timestamp.
Once done, you will be able to load these files by using the