2014-01-13 57 views
0

我知道你可以通過運行這個命令來運行所有datafixtures:運行特定datafixture + Symfony2的

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類位於T:

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(); 
     } 
    } 
} 

?> 

回答

1

嘗試

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

錯誤:[InvalidArgumentException] 找不到任何夾具來加載: -/src目錄/ VolleyScout/VolleyScoutBundle/DataFixtures/ORM – nielsv

+0

,不會是負載所有datafixtures,而不是一個具體的? – nielsv

+0

你可以發佈'LoadRegionData'實現嗎? – zizoujab

0

與試用完整路徑:

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