-2

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

[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.

这是我的夹具类:

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;
    }
}
4

1 回答 1

2

此异常与 symfony2 或教义夹具无关 - 这是一个通用的 PHP 异常。

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

$this->addReference("award-" .$i, $award);
于 2013-11-12T17:32:32.493 回答