Search code examples
symfonydoctrine-ormloadingfixtures

Why can't load data these fixtures in Symfony2 project?


I've created a fixtures class inside my bundle's DataFixtures/ORM folder. The actual class looks like this:

use Doctrine\Common\DataFixtures\FixtureInterface,
    Company\ShoppingBundle\Entity\Category;

class CategoryFixtures implements FixtureInterface
{
    public function load($em)
    {
        $category1 = new Category()->setName("category1");
        $category2 = new Category()->setName("category2");
        $em->persist($category1);
        $em->persist($category2);
        $em->flush();
    }
}

I'm not using the AbstractFixture base class, since I don't need references. I've also tried specifying the fixtures path when running the doctrine:fixtures:load console command. I'm following the official docs here.


Solution

  • Nothing wrong with the file naming, or my configuration: I simply forgot to put

    <?php
    

    at the top of my file :-D