1

我正在做一个 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/控制台原则: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

但是数据库中没有发生任何事情(仍然是空的)。

我在用 :

  • Ubuntu 16.04
  • Symfony 3.2
  • MongoDB 3.4.4
  • PHP 7.0.23

有任何想法吗 ? 谢谢。

4

1 回答 1

2

您需要持久化$customer对象:

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

你能试试吗?

于 2017-09-13T15:19:41.493 回答