8

I am a Symblog 2 beginner and I'm following this tutorial for Symblog2.

I have created my Data Model and tried to populate test data to my DB using Doctrine 2 fixtures.

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

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

and the follwing to AppKernel.php:

new Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle(),

My fixtures 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'm getting the following Exception:

Fatal error: Declaration of Soccer\MainBundle\DataFixtures\ORM\TeamFixtures::load() 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 the FixtureInterface::load.

Could someone tell me, what I'm missing? I followed the tutorial step by step.

7
  • You have downloaded components that are not compatible with each other. Double check you downloaded the right code and in the right version/revision.
    – hakre
    Jan 30, 2012 at 16:16
  • I downloaded the newest revision from git with the php bin/vendors install command, so I think, the versions should be compatible
    – Stefan S
    Jan 30, 2012 at 16:36
  • Well think what you want, PHP itself which needs to execute the stuff tells you that stuff does not work together. So as PHP needs to do the job, probably better trust PHP? Also I would double check the autoloader configuration, not all same parts of the namespaces share the same directory while they are from the same vendor, aren't they? I could be wrong, but this looks somewhat suspicious.
    – hakre
    Jan 30, 2012 at 16:38
  • Well, I found out, that doctrine wants the load function to be defined as public function load(ObjectManager $manager) instead of function load($manager). Thanks for your help.
    – Stefan S
    Jan 30, 2012 at 16:44
  • 1
    Well if it's the tutorial code, then use the versions given in the tutorial (or change your copy of the tutorial code). As long as you don't modify the libraries third-party code, I won't bother much. The tutorial might just have been outdated. Please add your solution as an answer, others might use that tutorial as well and run into the same problem.
    – hakre
    Jan 30, 2012 at 17:13

3 Answers 3

11

The FixtureInterface::load() method has a type hint since v1.0.0-ALPHA2:

use Doctrine\Common\Persistence\ObjectManager;

function load(ObjectManager $manager);
4
  • thanks, I already figured that out but had to wait to answer my own post
    – Stefan S
    Jan 30, 2012 at 20:18
  • 2
    I had to also use Doctrine\Common\Persistence\ObjectManager
    – gview
    Mar 22, 2012 at 1:18
  • @gview you can add the dependency "use Doctrine\Common\Persistence\ObjectManager;" and then declare the method as "function load(ObjectManager $manager)" Mar 31, 2012 at 2:00
  • Yes, that is what I stated "use Doctrine\Common\Persistence\ObjectManager"
    – gview
    Mar 31, 2012 at 3:37
8

You should add the ObjectManager dependency:

use Doctrine\Common\Persistence\ObjectManager;
0

As gview suggested with the use Doctrine\Common\Persistence\ObjectManager because function load(ObjectManager $manager); the ObjectManager need to know where it's corresponding class resides.
Thanks you this help me on SF2.16

They point this issue out here!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.