コード例 #1
0
 public function createAction()
 {
     $em = $this->get('doctrine')->getEntityManager();
     // Let's create a new thing
     $thing = new Thing();
     $thing->setName('Lorem' . \uniqid());
     // This does not actually save the entity but rather mark it
     // as "should-be-saved-on-the-next-flush"
     $em->persist($thing);
     // ... and let's create a new category!
     // Yes sir, we are in a good mood today.
     $category = new Category();
     $category->setName('Category' . \uniqid());
     $thing->setCategory($category);
     $em->persist($category);
     // Now we save everything: let's flush!
     $em->flush();
     return $this->render('KnpIpsumBundle:DoctrineOrm:create.html.twig', array('thing' => $thing));
 }
コード例 #2
0
ファイル: ThingFixtures.php プロジェクト: chazer/KnpIpsum
 public function load(ObjectManager $em)
 {
     $cat = new Thing();
     $cat->setName('Edgar the Cat');
     $bull = new Thing();
     $bull->setName('Joe the bull');
     $categoryRed = new Category();
     $categoryRed->setName('Red');
     $cat->setCategory($categoryRed);
     $bull->setCategory($categoryRed);
     for ($i = 0; $i < 20; $i++) {
         $thing = new Thing();
         $thing->setName('Dummy thing ' . $i);
         $thing->setCategory($categoryRed);
         $em->persist($thing);
     }
     $em->persist($cat);
     $em->persist($bull);
     $em->persist($categoryRed);
     $em->flush();
 }
コード例 #3
0
ファイル: FeatureContext.php プロジェクト: chazer/KnpIpsum
 /**
  * @Given /^there are (\d+) things in database$/
  */
 public function thereAreThingsInDatabase($count)
 {
     $this->thereAreNoThingsInDatabase();
     $em = $this->getEntityManager();
     for ($i = 0; $i < intval($count); $i++) {
         $thing = new Thing();
         $thing->setName('Lorem #' . $i);
         $em->persist($thing);
     }
     $em->flush();
 }