使用symfony 3.2中的Fixtures数据填充mongoDB

时间:2017-09-13 14:54:09

标签: mongodb symfony php-mongodb

我正在研究一个Symfony项目,我正在尝试将一些数据填充到mongoDB中,这就是我所做的:

<?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("wajdi.benabdallah@smarttouchtunisie.com");
        $customer->setPhone("28812010");
        $customer->setPassword("");

        $manager->flush();
    }
}
  

php bin / console doctrine:mongodb:fixtures:load

然后我收回了这些结果:

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

有什么想法吗? 谢谢你。

1 个答案:

答案 0 :(得分:1)

您需要保留$customer对象:

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

你能试试吗?

相关问题