Fatal error when using devices with doctrine 2

I am new to Symblog 2 and follow this tutorial for Symblog2 .

I created my data model and tried to fill in the test data of my database using Doctrine 2 devices .

I downloaded the necessary packages and added to my autoload.php :

 'Doctrine\\Common\\DataFixtures' => __DIR__.'/../vendor/doctrine-fixtures/lib', 'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib', 

and the following to AppKernel.php :

 new Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle(), 

My lighting class looks like this:

 <?php namespace Soccer\MainBundle\DataFixtures\ORM; use Doctrine\Common\DataFixtures\FixtureInterface; use Soccer\MainBundle\Entity\Team; class TeamFixtures implements FixtureInterface { public function load($manager) { $team1 = new Team(); $team1->setName('Poland'); $team1->setImg('./img/POL.png'); $team1->setKitHome('./img/POL_1.png'); $team1->setKitAway('./img/POL_2.png'); $manager->persist($team1); $manager->flush(); } } 

When I try to run php app/console doctrine:fixtures:load , I get the following exception:

Fatal error: Soccer \ MainBundle \ DataFixtures \ ORM \ TeamFixtures :: load () declaration must be compatible with that of Doctrine \ Common \ DataFixtures \ FixtureInterface :: load () in D: \ xampp \ htdocs \ soccertips \ em-symfony \ src \ Soccer \ MainBundle \ DataFixtures \ ORM \ TeamFixtures.php on line 8

 Call Stack: 0.0004 328688 1. {main}() D:\xampp\htdocs\soccertips\em-symfony\app\console:0 0.0283 2043272 2. Symfony\Component\Console\Application->run() D:\xampp\htdocs\soccertips\em-symfony\app\console:22 0.0344 2230520 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:118 3.3961 18394992 4. Symfony\Component\Console\Application->doRun() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:75 3.3998 18394992 5. Symfony\Component\Console\Command\Command->run() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:194 3.4006 18395336 6. Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Command\Command.php:224 3.4056 18499160 7. Doctrine\Common\DataFixtures\Loader->loadFromDirectory() D:\xampp\htdocs\soccertips\em-symfony\vendor\bundles\Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand.php:97 3.4084 18509624 8. require_once('D:\xampp\htdocs\soccertips\em-symfony\src\Soccer\MainBundle\DataFixtures\ORM\TeamFixtures.php') D:\xampp\htdocs\soccertips\em-symfony\vendor\doctrine-fixtures\lib\Doctrine\Common\DataFixtures\Loader.php:92 

I understand the error message, but in my opinion my load() method is compatible with FixtureInterface::load .

Can someone tell me what i miss? I followed the tutorial step by step.

+7
source share
3 answers

The FixtureInterface :: load () method has a tooltip type with v1.0.0-ALPHA2 :

 use Doctrine\Common\Persistence\ObjectManager; function load(ObjectManager $manager); 
+10
source

You must add an ObjectManager dependency:

 use Doctrine\Common\Persistence\ObjectManager; 
+8
source

As follows from gview using Doctrine \ Common \ Persistence \ ObjectManager, since function load(ObjectManager $manager); The ObjectManager must know where the corresponding class is located.
Thank you, this will help me on SF2.16

They point out this problem here!

0
source

All Articles