我正在研究一个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
但数据库中没有发生任何事情(仍为空)。
我正在使用:
有什么想法吗? 谢谢你。
答案 0 :(得分:1)
您需要保留$customer
对象:
$manager->persist($customer); // Store in database.
你能试试吗?