Pages

Getting started
The ModularRouting component makes it easy to configure dynamic routes by defining reusable modules. ModularBundle integrates this functionality directly into the Symfony framework. This page shows how to configure the bundle by using Symfony CMF's RoutingBundle to enable the use of multiple routers. # Installation ## Download the bundle Start by requiring the bundles in Composer: $ composer require symfony-cmf/routing-bundle "~2.0" $ composer require harmony-project/modular-bundle "dev-master" Composer will install the required libraries into your `vendor` directory and add the dependencies to your `composer.json` file. ## Enable the bundles Enable the required bundles by registering them in your `AppKernel` class: <?php // app/AppKernel.php public function registerBundles() { $bundles = [ // ... new \Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(), new \Harmony\Bundle\ModularBundle\HarmonyModularBundle(), // ... ]; } ## Create the module entity Create a module entity by implementing `ModuleInterface` or by extending the base `Module` class provided by the ModularRouting component. The router uses the `modularType` field of the module to match the correct routing metadata to the request. This is an example of how the module entity should look if you're using the Doctrine ORM: <?php // src/AppBundle/Entity/Module.php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Harmony\Component\ModularRouting\Model\Module as BaseModule; /** * @ORM\Entity * @ORM\Table(name="module") */ class Module extends BaseModule { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var string * * @ORM\Column(name="modular_type", type="string", length=255) */ protected $modularType; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Get modular identity * * @return mixed */ public function getModularIdentity() { return $this->getId(); } // custom methods... } ## Configure the bundle Add the following configuration to your project's configuration file: # app/config/config.yaml # Harmony Modular Configuration harmony_modular: module_class: AppBundle\Entity\Module module_identifier: 'id' route_prefix: '/module' router: resource: '%kernel.root_dir%/config/modular_routing.yml' Only the `module_class` option is required to activate the bundle. For a complete overview of the available configuration options, see the [[[11]]]. The CMF RoutingBundle does not need any configuration to function, since ModularRouter is enabled by default and will only be triggered after the default Symfony router. It's possible to change the priority of ModularRouter with it's service handle `harmony_modular.router`. See the [CMF RoutingBundle documentation][cmf-routing-configuration] for an overview of the available configuration options. ## Create the module metadata Before being able to use a module, you need to tell the project of it's existence by creating metadata definitions. This is an example of what basic metadata definitions look like: # app/config/modular_routing.yml foo_module: name: "Foo Module" type: "foo" routing: - { resource: "@AppBundle/Controller/FooController.php", type: "annotation" } bar_module: name: "Bar Module" type: "bar" routing: - { resource: "app/config/routing/bar_module.yml", type: "yml" } # import module definitions acme: resource: "@AcmeBundle/Resources/config/modular_routing.yml" type: yaml [cmf-routing-configuration]: http://symfony.com/doc/current/cmf/bundles/routing/configuration.html
Configuration reference
This is an overview of the available configuration options for ModularBundle. # Full configuration harmony_modular: module_class: null module_identifier: null route_prefix: prefix: '/module' defaults: [] requirements: [] router: resource: # required, needs testing if undefined! resource_type: null service: module_manager: harmony_modular.module_manager.doctrine provider: harmony_modular.provider.segment # Configuration options ## module_class type: `string` default: `null` The fully qualified class name of the `Module` object. If this setting is not present (or is `null`) the bundle will not be enabled. ## module_identifier type: `string` default: `null` A value used by module managers to identify a module. For example, when using the Doctrine ORM the default value is `id`. Make sure the `getModularIdentity()` method of the module object returns the expected value as well. ## route_prefix ### prefix type: `string` default: `/module` A routing prefix for all modular routes. To omit the prefix entirely enter `/`. You can also set this value directly to `route_prefix`: harmony_modular: route_prefix: '/module' ### defaults type: `array` default: `array()` ### requirements type: `array` default: `array()` ## router ## service