edit composer.json // nak download yang latest
tambah :
"require": { // ... "doctrine/doctrine-fixtures-bundle": "dev-master", "doctrine/data-fixtures" : "dev-master" }
run :
php composer.phar update
register bundle dekat
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), // ... ); // ... }
Create a fixture file di src/ASF/PembedaBundle/DataFixtures/ORM/SurahFixtures.php
// src/ASF/PembedaBundle/DataFixtures/ORM/SurahFixtures.php
namespace ASF\PembedaBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use ASF\PembedaBundle\Entity\Surah;
//class SurahFixtures implements FixtureInterface
class SurahFixtures extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
$surah1 = new Surah();
$surah1->setId('001');
$surah1->setIndex(1);
$surah1->setBilayat(7);
$surah1->setMulaayat(0);
$surah1->setNama("الفاتحة");
$surah1->setTnama('Al-Faatihah');
$surah1->setEnama('The Opening');
$surah1->setMnama('Pembukaaan');
$surah1->setCategory('Mekah');
$surah1->setOrder(5);
$surah1->setRukus(1);
$surah1->setPengenalan('');
$surah1->setImage('alquran.jpg');
$surah1->setTags('jalan, iman, islam');
$surah1->setCreated(new \DateTime());
$surah1->setUpdated($surah1->getCreated());
$manager->persist($surah1);
$surah2->setId('002');
$surah2->setIndex(2);
$surah2->setBilayat(286);
$surah2->setMulaayat(7);
$surah2->setNama("البقرة");
$surah2->setTnama('Al-Baqara');
$surah2->setEnama('The Cow');
$surah2->setMnama('Lembu Betina');
$surah2->setCategory('Madinah');
$surah2->setOrder(87);
$surah2->setRukus(40);
$surah2->setPengenalan('');
$surah2->setImage('alquran.jpg');
$surah2->setTags('jalan, iman, islam');
$surah2->setCreated(new \DateTime());
$surah2->setUpdated($surah2->getCreated());
$manager->persist($surah2);
$manager->flush();
$this->addReference('surah-1', $surah1);
$this->addReference('surah-2', $surah2);
}
loading the fixtures to database
php app/console doctrine:fixtures:load
No comments:
Post a Comment