“Symfony Datafixtures” Réponses codées

luminaires Symfony

php bin/console doctrine:fixtures:load
Hakamate

Symfony Datafixtures

<?php

namespace App\DataFixtures;

use App\Entity\Article;
use App\Entity\Category;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Faker;

class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $faker = Faker\Factory::create('fr-FR');
        for ($count = 0; $count < 10; $count++) {
            // Category
            $category = new Category();
            $category->setName($faker->word());
            $manager->persist($category);
    
            // Article
            $article = new Article();
            $article->setTitle($faker->word());
            $article->setDate($faker->dateTime());
            $article->setVisible($faker->boolean());
            $article->setContent($faker->paragraph());
            $article->setIdCat($category);
            $manager->persist($article);

        }

        $manager->flush();
    }
}
Testy Termite

Réponses similaires à “Symfony Datafixtures”

Questions similaires à “Symfony Datafixtures”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code