使用来自 symfony 3.2 的 Fixtures 数据填充 mongoDB
Fill mongoDB with Fixtures data from symfony 3.2
我正在做一个 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
有什么想法吗?
谢谢。
您需要保留 $customer
对象:
$manager->persist($customer); // Store in database.
你能试试吗?
我正在做一个 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
有什么想法吗? 谢谢。
您需要保留 $customer
对象:
$manager->persist($customer); // Store in database.
你能试试吗?