2017-09-13 16 views
1

我工作的一个symfony项目灯具的数据,我想填补一些夹具数据MongoDB的,这就是我所做的:填写的MongoDB从symfony的3.2

<?php 

namespace FrontOfficeBundle\DataFixtures\ORM; 

use FrontOfficeBundle\Document\Customer; 
use Doctrine\Bundle\FixturesBundle\Fixture; 
use Doctrine\Common\Persistence\ObjectManager; 

class Fixtures extends Fixture 
{ 
    public function load(ObjectManager $manager) 
    { 
     $customer = new Customer(); 
     $customer->setName("Ben Abdallah"); 
     $customer->setSurename("Wajdi"); 
     $customer->setUsername("wajdibenabdallah"); 
     $customer->setEmail("[email protected]"); 
     $customer->setPhone("28812010"); 
     $customer->setPassword(""); 

     $manager->flush(); 
    } 
} 

PHP斌/控制台学说:MongoDB的:灯具:负载

,然后我回到这些结果:

Careful, database will be purged. Do you want to continue (y/N) ?y 
    > purging database 
    > loading Doctrine\Bundle\FixturesBundle\EmptyFixture 
    > loading FrontOfficeBundle\DataFixtures\ORM\Fixtures 

但诺斯在数据库中发生了(仍然是空的)。

我'使用:

  • ubuntuu 16.04
  • Symfony的3.2
  • 的MongoDB 3.4.4
  • PHP 7.0.23

任何想法? 谢谢你。

回答

0

你需要坚持的$customer对象:

$manager->persist($customer); // Store in database. 

你可以试试吗?

+0

谢谢,它现在正在工作! –