2015-07-21 65 views
0

我用hautelook /翹bundleand我需要爲我的開發人員負載能力我寫SkillsLoader.php:燈具愛麗絲Symfony的

class LoadSkillssData extends AbstractFixture implements OrderedFixtureInterface 
{ 
public function load(ObjectManager $manager) 
{ 
    $all_skills = 
     [ 
      'doctrine 2', 
      'Memcache', 
      'QA', 
      'testing', 
      'web design', 
      'EJB 3' 
     ]; 
    for ($i = 1; $i<=172; $i++) 
    { 
     $skills = new Skills(); 
      $skills -> setId($i); 
      $skills ->setSkill($all_skills[$i]); 
     $manager->persist($skills); 
     $manager->flush(); 

    } 
} 

public function getOrder() 
{ 
    return 1; // the order in which fixtures will be loaded 
} 

但我創建實體技能SETID(),因爲我有錯誤ID不能爲空。但我的問題是如何使用YML文件我CANU PLOAD技能fixteures,這是愛麗絲bundleand我

Artel\CustomerBundle\Entity\Cities: 
cities{1..50}: 
city: <city()> 

Artel\CustomerBundle\Entity\Developers: 
users{1..20}: 
location: @cities* 
level: <?php $names = ['Junior', 'Middle', 'Senior']; echo $names[array_rand($names)]; ?> 
main_skill: @skills* 
firstName: <firstName()> 
lastName: <lastName()> 
username: <firstNameMale()> 
telephone: <phoneNumber()> 
skype: skypeName 
email: <email()> 
password: <password()> 
roles: <?php $names = ['ROLE_ADMIN', 'ROLE_USER', 'ROLE_AGENT', 'ROLE_COMPANY']; echo $names[array_rand($names)]; ?> 

Artel\CustomerBundle\Entity\Skills: 
skills{1..30}: 
skill: ???? 

回答

0

This tutorial什麼都有覆蓋。您可以爲每個實體創建不同的YAML文件,並按正確的順序(依賴關係)加載它們,然後在其他裝置中引用技能。

如果您的問題是從YAML文件中創建技巧需要構造調用,那麼也可以這樣做(如教程中所示)。

相關問題