我正在使用 Symfony2 实现经典的博客应用程序,并且“应用程序/控制台学说:fixtures:load”返回错误。我的 BlogFixtures.php 文件是这样的:
<?php
namespace MGF\Bundles\WebBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use MGF\Bundles\WebBundle\Entity\Blog;
use MGF\Bundles\CRMBundle\Util\Util;
class BlogFixtures extends AbstractFixture implements FixtureInterface
{
public function load(ObjectManager $em)
{
$blog1 = new Blog();
$title = 'First post';
$blog1->setTitle($title);
$slug1 = Util::getSlug($title);
$blog1->setSlug($slug1);
$blog1->setImage('beach.jpg');
$blog1->setTags('symfony2, php, paradise, symblog');
$blog1->setCreated(new \DateTime('now'));
$blog1->setUpdated($blog1->getCreated());
$em->persist($blog1);
$author1 = $em->getRepository('MGFBCBundle:User')->findOneByUser('sarah');
$author1->addBlog($blog1);
$em->persist($author1);
$em->flush();
}
}
和错误:
app/console doctrine:fixtures:load
Careful, database will be purged. Do you want to continue Y/N ?Y
> purging database
> loading MGF\Bundles\WebBundle\DataFixtures\ORM\BlogFixtures
PHP Fatal error: Call to a member function addBlog() on a non-object in /var/www/METRO/src/MGF/Bundles/WebBundle/DataFixtures/ORM/BlogFixtures.php on line 33
Fatal error: Call to a member function addBlog() on a non-object in /var/www/METRO/src/MGF/Bundles/WebBundle/DataFixtures/ORM/BlogFixtures.php on line 33
我看不出我哪里错了。有什么提示吗?
提前致谢。