Fixtures Symfony
php bin/console doctrine:fixtures:load
Hakamate
php bin/console doctrine:fixtures:load
<?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();
}
}