Fixtures Alice Symfony

1.5k Views Asked by At

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

There are 1 best solutions below

0
On

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).