You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you don't have Doctrine data-fixtures configured with Symfony2 follow the steps here.
7
+
Fixtures are used to load the database with a set of data. This data can either be for testing or could be the initial data required for the application to run smoothly. Symfony2 has no built in way to manage fixtures but Doctrine2 has a library to help you write fixtures for ORM and ODM.
7
8
8
-
Add the following to `bin/vendors.sh`
9
+
Setup and Configuration
10
+
-----------------------
11
+
12
+
If you don't have `Doctrine Data Fixtures`_ configured with Symfony2 yes, follow these steps to do so.
The ideal place to store your fixtures is inside ``Vendor/MyBundle/DataFixtures/ORM`` and ``Vendor/MyBundle/DataFixtures/ODM`` respectively for ORM and ODM.
23
38
24
-
`TODO: Add a simple fixture, ORM and ODM`
39
+
In this tutorial we will assume you are using ORM. If you are using ODM make the changes as required.
25
40
26
-
##Sharing Objects Between Fixtures
41
+
In our first fixture we will add a default user to the table of ``User`` entity.
use Doctrine\Common\DataFixtures\FixtureInterface;
52
+
use Vendor\MyBundle\Entity\User; //Modify this to use your entity
53
+
54
+
class LoadUserData implements FixtureInterface
55
+
{
56
+
public function load($manager)
57
+
{
58
+
$userAdmin = new User();
59
+
$userAdmin->setUsername('admin');
60
+
$userAdmin->setPassword('test');
31
61
62
+
$manager->persist($userAdmin);
63
+
$manager->flush();
64
+
}
65
+
}
66
+
67
+
Writing fixtures this way is quite easy and simple but is not sufficient when you are building something serious. The most serious limitation is that you can not share objects between fixtures. Lets see how we can overcome this limitation in the next section.
0 commit comments