This version of the bundle requires Symfony 2.1+.
- Download IRZoneBundle using composer
- Enable the Bundle
- Create your classes
- Configure the IRZoneBundle
- Import IRZoneBundle routing
- Update your database schema
Add IRZoneBundle in your composer.json:
{
"require": {
"informaticrevolution/zone-bundle": "*"
}
}
Now tell composer to download the bundle by running the command:
$ php composer.phar update informaticrevolution/zone-bundle
Enable the bundle in the kernel:
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new IR\Bundle\ZoneBundle\IRZoneBundle(),
);
}
a) Create your Zone class
<?php
// src/Acme/ZoneBundle/Entity/Zone.php
namespace Acme\ZoneBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use IR\Bundle\ZoneBundle\Model\Zone as BaseZone;
/**
* @ORM\Entity
* @ORM\Table(name="acme_zone")
*/
class Zone extends BaseZone
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
<?php
// src/Acme/ZoneBundle/Entity/Zone.php
namespace Acme\ZoneBundle\Entity;
use IR\Bundle\ZoneBundle\Model\Zone as BaseZone;
/**
* Zone implementation.
*/
class Zone extends BaseZone
{
}
In YAML:
# src/Acme/ZoneBundle/Resources/config/doctrine/Zone.orm.yml
Acme\ZoneBundle\Entity\Zone:
type: entity
table: acme_zone
id:
id:
type: integer
generator:
strategy: AUTO
In XML:
<!-- src/Acme/ZoneBundle/Resources/config/doctrine/Zone.orm.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Acme\ZoneBundle\Entity\Zone" table="acme_zone">
<id name="id" type="integer" column="id">
<generator strategy="AUTO" />
</id>
</entity>
</doctrine-mapping>
b) Create your Country class
Warning:
If you override the __construct() method in your Country class, be sure to call parent::__construct(), as the base Country class depends on this to initialize some fields.
<?php
// src/Acme/ZoneBundle/Entity/Country.php
namespace Acme\ZoneBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use IR\Bundle\ZoneBundle\Model\Country as BaseCountry;
/**
* @ORM\Entity
* @ORM\Table(name="acme_country")
*/
class Country extends BaseCountry
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Province", mappedBy="country", cascade={"all"}, orphanRemoval=true)
* @ORM\OrderBy({"name" = "ASC"})
*/
protected $provinces;
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
// your own logic
}
}
<?php
// src/Acme/ZoneBundle/Entity/Country.php
namespace Acme\ZoneBundle\Entity;
use IR\Bundle\ZoneBundle\Model\Country as BaseCountry;
/**
* Country implementation.
*/
class Country extends BaseCountry
{
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
// your own logic
}
}
In YAML:
# src/Acme/ZoneBundle/Resources/config/doctrine/Country.orm.yml
Acme\ZoneBundle\Entity\Country:
type: entity
table: acme_country
id:
id:
type: integer
generator:
strategy: AUTO
oneToMany:
provinces:
targetEntity: Province
mappedBy: country
cascade: [ all ]
orphanRemoval: true
orderBy: { name: ASC }
In XML:
<!-- src/Acme/ZoneBundle/Resources/config/doctrine/Country.orm.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Acme\ZoneBundle\Entity\Country" table="acme_country">
<id name="id" type="integer" column="id">
<generator strategy="AUTO" />
</id>
<one-to-many field="provinces" target-entity="Province" mapped-by="country" orphan-removal="true">
<cascade>
<cascade-all />
</cascade>
<order-by>
<order-by-field name="name" direction="ASC" />
</order-by>
</one-to-many>
</entity>
</doctrine-mapping>
c) Create your Province class
<?php
// src/Acme/ZoneBundle/Entity/Province.php
namespace Acme\ZoneBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use IR\Bundle\ZoneBundle\Model\Province as BaseProvince;
/**
* @ORM\Entity
* @ORM\Table(name="acme_province")
*/
class Province extends BaseProvince
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
<?php
// src/Acme/ZoneBundle/Entity/Province.php
namespace Acme\ZoneBundle\Entity;
use IR\Bundle\ZoneBundle\Model\Province as BaseProvince;
/**
* Province implementation.
*/
class Province extends BaseProvince
{
}
In YAML:
# src/Acme/ZoneBundle/Resources/config/doctrine/Province.orm.yml
Acme\ZoneBundle\Entity\Province:
type: entity
table: acme_province
id:
id:
type: integer
generator:
strategy: AUTO
In XML:
<!-- src/Acme/ZoneBundle/Resources/config/doctrine/Province.orm.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Acme\ZoneBundle\Entity\Province" table="acme_province">
<id name="id" type="integer" column="id">
<generator strategy="AUTO" />
</id>
</entity>
</doctrine-mapping>
Add the bundle minimum configuration to your config.yml
file:
a) Add the zone configuration
# app/config/config.yml
ir_zone:
db_driver: orm # orm is the only available driver for the moment
zone_class: Acme\ZoneBundle\Entity\Zone
country_class: Acme\ZoneBundle\Entity\Country
province_class: Acme\ZoneBundle\Entity\Province
b) Add the ZoneInterface and CountryInterface path to the RTEL
# app/config/config.yml
doctrine:
# ....
orm:
# ....
resolve_target_entities:
IR\Bundle\ZoneBundle\Model\ZoneInterface: Acme\ZoneBundle\Entity\Zone
IR\Bundle\ZoneBundle\Model\CountryInterface: Acme\ZoneBundle\Entity\Country
Add the following configuration to your routing.yml
file:
# app/config/routing.yml
ir_zone_admin:
resource: "@IRZoneBundle/Resources/config/routing.xml"
prefix: /admin
Run the following command:
$ php app/console doctrine:schema:update --force