运行特定的datafixture + Symfony2

时间:2014-01-13 16:01:50

标签: php symfony path

我知道您可以通过运行此命令来运行所有数据固定:

php app/console doctrine:fixtures:load

并且您可以通过运行此命令来运行特定的夹具:

php app/console doctrine:fixtures:load --fixtures=/path/to/fixture1 

但是现在我正在尝试第二个命令来加载这样的特定数据包:

php app/console doctrine:fixtures:load --fixtures=/src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData

我的LoadRegionData类位于:

src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData.php

当我运行命令时,我总是会收到以下错误:

[InvalidArgumentException]
Could not find any fixtures to load in:

- /src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM/LoadRegionData

LoadRegionData.php

<?php

namespace VolleyScout\VolleyScoutBundle\DataFixtures\ORM;

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

use VolleyScout\VolleyScoutBundle\Entity\Regions;

class LoadRegionData implements FixtureInterface
{
    /**
    * {@inheritDoc}
    */
    public function load(ObjectManager $manager)
    {
        $regions = ['West-Vlaanderen', 'Oost-Vlaanderen', 'Antwerpen', 'Vlaams-Brabant', 'Limburg', 'Vlaanderen'];

        foreach($regions as $r){
            $region = new Regions();
            $region->setRegionName($r);
            $region->setRegionDescription($r);
            $manager->persist($region);
            $manager->flush();
        }
    }
}

?>

2 个答案:

答案 0 :(得分:1)

尝试

php app/console doctrine:fixtures:load --fixtures=src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM

答案 1 :(得分:0)

尝试使用完整路径:

php app/console doctrine:fixtures:load --fixtures=/Users/foobar/projects/projectname/src/VolleyScout/VolleyScoutBundle/DataFixtures/ORM