Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (70 sloc) 3.114 kb
e7b7d77 @willdurand Rewrote the documentation
willdurand authored
1 The Fixtures
2 ============
3
4 Fixtures are data you usually write to populate your database during the development, or static content
5 like menus, labels, ... you need by default in your database in production.
6
7 ## Loading Fixtures ##
8
9 The following command is designed to load fixtures:
10
11 > php app/console propel:fixtures:load [-d|--dir[="..."]] [--xml] [--sql] [--yml] [--connection[="..."]] [bundle]
12
13 As you can see, there are many options to allow you to easily load fixtures.
14
15 As usual, `--connection` allows to specify a connection. The `--dir` option allows to specify a directory
16 containing the fixtures (default is: `app/propel/fixtures/`).
17 Note that the `--dir` expects a relative path from the root dir (which is `app/`).
18
19 The `--xml` parameter allows you to load only XML fixtures.
20 The `--sql` parameter allows you to load only SQL fixtures.
21 The `--yml` parameter allows you to load only YAML fixtures.
22
23 You can mix `--xml`, `--yml` and `--sql` parameters to load XML, YAML and SQL fixtures at the same time.
24 If none of this parameter are set all files YAML, XML and SQL in the directory will be load.
25
26 You can pass a bundle name to load fixtures from it. A bundle's name starts with `@` like `@AcmeDemoBundle`.
27
28 > php app/console propel:fixtures:load @AcmeDemoBundle
29
30
31 ### XML Fixtures ###
32
33 A valid _XML fixtures file_ is:
34
35 ``` xml
36 <Fixtures>
37 <Object Namespace="Awesome">
38 <o1 Title="My title" MyFoo="bar" />
39 </Object>
40 <Related Namespace="Awesome">
41 <r1 ObjectId="o1" Description="Hello world !" />
42 </Related>
43 </Fixtures>
44 ```
45
46
47 ### YAML Fixtures ###
48
49 A valid _YAML fixtures file_ is:
50
51 ``` yaml
52 Awesome\Object:
53 o1:
54 Title: My title
55 MyFoo: bar
56
57 Awesome\Related:
58 r1:
59 ObjectId: o1
60 Description: Hello world !
61
62 Awesome\Tag:
63 t1:
64 name: Foo
65 t2:
66 name: Baz
67
68 Awesome\Post:
69 p1:
70 title: A Post with tags (N-N relation)
71 tags: [ t1, t2 ]
72 ```
73
74
75 #### Using Faker in YAML Fixtures ####
76
77 If you use [Faker](https://github.com/fzaninotto/Faker) with its [Symfony2 integration](https://github.com/willdurand/BazingaFakerBundle),
78 then the PropelBundle offers a facility to use the Faker generator in your YAML files:
79
80 ``` yml
81 Acme\DemoBundle\Model\Book:
82 Book1:
83 name: "Awesome Feature"
84 description: <?php $faker('text', 500); ?>
85 ```
86
87 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
88 add data tou your application, but most of the time you need to rely on real data. To integrate Faker in the YAML files
89 allows to write strong fixtures efficiently.
90
91
92 ## Dumping data ##
93
94 You can dump data from your database into YAML fixtures file by using this command:
95
96 > php app/console propel:fixtures:dump [--connection[="..."]]
97
98 Dumped files will be written in the fixtures directory: `app/propel/fixtures/` with the following name:
99 `fixtures_99999.yml` where `99999` is a timestamp.
100
101 Once done, you will be able to load these files by using the `propel:fixtures:load` command.
102
103
104 [Back to index](index.markdown)
Something went wrong with that request. Please try again.