Fatal error: Call to a member function persist() on a non-object
我正在使用作曲家,mongodb学说,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());
您的示例中尚未定义$dm
变量。请尝试:
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$dm->persist($car);
$dm->flush();
它在文档中有很好的描述 - http://symfony.com/doc/2.0/bundles/DoctrineMongoDBBundle/index.html