PHP code example of sympress / doctrine-fixtures-bundle

1. Go to this page and download the library: Download sympress/doctrine-fixtures-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sympress / doctrine-fixtures-bundle example snippets


// config/services.php
$services = $container->services()->defaults()->autowire()->autoconfigure();
$services->load('App\\DataFixtures\\', '%kernel.project_dir%/src/DataFixtures');

namespace App\DataFixtures;

use App\Entity\Product;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

final class ProductFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $manager->persist(new Product('Demo product'));
        $manager->flush();
    }
}

use SymPress\DoctrineFixturesBundle\RevertibleFixtureInterface;

final class ProductFixtures extends Fixture implements RevertibleFixtureInterface
{
    public function load(ObjectManager $manager): void
    {
        $product = new Product('Demo product');
        $manager->persist($product);
        $manager->flush();
        $this->addReference('product.demo', $product);
    }

    public function down(ObjectManager $manager): void
    {
        $manager->remove($this->getReference('product.demo', Product::class));
    }
}