简体   繁体   中英

Fixtures Alice Symfony

I use hautelook/alice-bundleand I need load skills for my developers I write SkillsLoader.php:

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
}

But I create setId() for entity skill, because I has error id can not be null. But my question how use alice-bundleand in yml file I canu pload skill fixteures, this is I have

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: ????

This tutorial has everything covered. You can create distinct YAML files for each entity and load them in the proper order (by dependency) and then reference skills in other fixtures.

If your issue is that creating the skill from within the YAML files required a construct call, you can do that too (as shown in the tutorial).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM