致命错误:在非对象上调用成员函数persist()

时间:2014-01-13 10:09:54

标签: php mongodb doctrine composer-php

Fatal error: Call to a member function persist() on a non-object

我正在使用作曲家,mongodb doctrine,php

namespace Documents;

public $document_id;
public $id;
public $model;
public function __construct($model){
     $this->model = $model;
     $car = new Car('Ford');
     dm->persist($car);
     dm->flush();
     var_dump($car->__toString());

1 个答案:

答案 0 :(得分:0)

您的示例中没有定义$dm变量。请尝试:

$dm = $this->get('doctrine.odm.mongodb.document_manager');
$dm->persist($car);
$dm->flush();

在文档中有详细描述 - http://symfony.com/doc/2.0/bundles/DoctrineMongoDBBundle/index.html