Note that there are some explanatory texts on larger screens.

plurals
  1. POError "Call to a member function on a non-object" when loading Symfony2 fixtures
    text
    copied!<p>I'm implementing the classic Blog app with Symfony2, and the "app/console doctrine:fixtures:load" returns an error. My BlogFixtures.php file is like this:</p> <pre><code>&lt;?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-&gt;setTitle($title); $slug1 = Util::getSlug($title); $blog1-&gt;setSlug($slug1); $blog1-&gt;setImage('beach.jpg'); $blog1-&gt;setTags('symfony2, php, paradise, symblog'); $blog1-&gt;setCreated(new \DateTime('now')); $blog1-&gt;setUpdated($blog1-&gt;getCreated()); $em-&gt;persist($blog1); $author1 = $em-&gt;getRepository('MGFBCBundle:User')-&gt;findOneByUser('sarah'); $author1-&gt;addBlog($blog1); $em-&gt;persist($author1); $em-&gt;flush(); } } </code></pre> <p>And the error:</p> <pre><code>app/console doctrine:fixtures:load Careful, database will be purged. Do you want to continue Y/N ?Y &gt; purging database &gt; 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 </code></pre> <p>I don't see where I go wrong. Any hints?</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload