[Symfony的\元器件\调试\异常\ ContextErrorException]

时间:2013-11-12 16:38:35

标签: mongodb symfony doctrine-orm fixtures

我正在制作灯具,当我尝试加载灯具时出现错误。奖和电影之间的关系是单向的,所以我加载了第一个奖,因为它没有任何参考。错误说:

[Symfony\Component\Debug\Exception\ContextErrorException] Warning: spl_object_hash()
expects parameter 1 to be object, array given in
/Users/benatespina/Development/filmboot.web/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM‌/MongoDB/UnitOfWork.php line 1706.

这是我的Fixture类:

namespace MyProject\MovieBundle\DataFixtures\MongoDB;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

use MyProject\MovieBundle\Document\Award;

class Awards extends AbstractFixture implements OrderedFixtureInterface {
    public function load(ObjectManager $manager) {
        $awards = array(
            array(
                "name"     => "Sitges",
                "year"     => "1992",
                "category" => "Best director"
        );

        foreach ($awards as $i => $award) {
            $document = new Award();
            $document->setName    ($award["name"]);
            $document->setYear    ($award["year"]);
            $document->setCategory($award["category"]);

            $manager->persist($document);
            $this->addReference("award-" . $i, $award);
        }

        $manager->flush();
    }

    public function getOrder() {
        return 1;
    }
}

1 个答案:

答案 0 :(得分:2)

此异常与symfony2或doctrine-fixtures无关 - 它是一个通用的PHP异常。

您正尝试使用从未在$i电话中定义的变量addReference()

$this->addReference("award-" .$i, $award);