Permalink
Browse files

Create a fixture to load dummy data into our database

Create the FormFixtures file to create data into the database Then run:
php app/console doctrine:fixtures:load --append
  • Loading branch information...
1 parent de7e698 commit 99667e3796d808898aa860eeff54c0c974836bac @cammanderson cammanderson committed Aug 2, 2011
Showing with 42 additions and 0 deletions.
  1. +42 −0 Symfony/src/MelbSymfony2/ForumExampleBundle/DataFixtures/ORM/ForumFixtures.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace MelbSymfony2\ForumExampleBundle\DataFixtures\ORM;
+
+use MelbSymfony2\ForumExampleBundle\Entity;
+use Doctrine\Common\DataFixtures\FixtureInterface;
+
+class ForumFixtures implements FixtureInterface
+{
+
+ /**
+ * Load data fixtures with the passed EntityManager
+ *
+ * @param object $manager
+ */
+ public function load($manager)
+ {
+ // TODO: Implement load() method.
+ for($userIndex = 0; $userIndex < 5; ++$userIndex)
+ {
+ for($index = 0; $index < 20; ++$index)
+ {
+ $thread = new Entity\Thread();
+ $thread->setTitle('thread: ' . $userIndex . ' - ' . $index);
+ $thread->setBody('body: ' . $userIndex . ' - ' . $index);
+
+ for($postIndex = 0; $postIndex < 50; ++$postIndex)
+ {
+ $post = new Entity\Post();
+ $post->setThread($thread);
+ $post->setTitle('title: ' . $userIndex . ' - ' . $index . ' - ' . $postIndex);
+ $post->setBody('body: ' . $userIndex . ' - ' . $index . ' - ' . $postIndex);
+ $manager->persist($post);
+ }
+
+ $manager->persist($thread);
+
+ }
+ }
+ $manager->flush();
+ }
+}

0 comments on commit 99667e3

Please sign in to comment.