0
votes

Im beginner with Symfony 2 (2.8.* version). I'm trying to load sample data to my database with fixture and faker. I've created src/AppBundle/DataFixtures/ORM directory and put there a LoadPostData.php file with this code:

<?php

namespace AppBundle\DataFixtures\ORM;


use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistance\ObjectManager;


class LoadPostData implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $faker = \Faker\Factory::create();

        for ($i = 1; $i < 200; $i++) {

            $post = new \AppBundle\Entity\Post();
            $post->setTitle($faker->sentence(3));
            $post->setLead($faker->text(300));
            $post->setContent($faker->text(800));
            $post->setCreatedAt($faker->dateTimeThisMonth);


            $manager->persist($post);
        }


        $manager->flush();
    }
}

But when I hit a command "php app/console doctrine:fixtures:load" in my terminal I get this error:

PHP Fatal error:  Declaration of AppBundle\DataFixtures\ORM\LoadPostData::load(Doctrine\Common\Persistance\O
bjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Common\Persist
ence\ObjectManager $manager) in /Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/
LoadPostData.php on line 10

Fatal error: Declaration of AppBundle\DataFixtures\ORM\LoadPostData::load(Doctrine\Common\Persistance\ObjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Common\Persistence\ObjectManager $manager) in /Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/LoadPostData.php on line 10

(line 10 is a declaration of LoadPostData class)

What do I do wrong here? I was following a tutorial step by step and have no idea what is missing. Thanks in advance!

1
Your load function should be public.ccKep
Right. I've fixed that but still I get the same error as beforeampher911
You also have a typo in "Persistance", it's called "Persistence": use Doctrine\Common\Persistence\ObjectManager;ccKep

1 Answers

1
votes

Grabbing the function call from your error message reveals your mistake:

Fatal error: Declaration of AppBundle\DataFixtures\ORM\LoadPostData::load(Doctrine\Common\Persistance\ObjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Common\Persistence\ObjectManager $manager) in /Users/myMac/Desktop/symfony2/Blog/src/AppBundle/DataFixtures/ORM/LoadPostData.php on line 10

The 2 declarations being:

::load(Doctrine\Common\Persistance\ObjectManager $manager)
::load(Doctrine\Common\Persistence\ObjectManager $manager)

You misspelled Persistence in your use statement.