2017 © Pedro Peláez
 

library mxc-routes

Zend Framework 2 Module that provides a new route to generate child route structures automatically according to a template configuration you provide.

image

mxc-commons/mxc-routes

Zend Framework 2 Module that provides a new route to generate child route structures automatically according to a template configuration you provide.

  • Tuesday, June 14, 2016
  • by fhein
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

MxcRoutes

Version 1.0.1 created by Frank Hein and the mxc-commons team., (*1)

MxcRoutes is part of the maxence Open Source Initiative by maxence business consulting gmbh, Germany., (*2)

Introduction

Tired of writing down the same routing configuration for your standard controller classes again and again? Then MxcRoutes may be something you have been waiting for., (*3)

MxcRoutes provides an additional route type which generates the child route structure automatically according to template you provide once., (*4)

Multiple child route models are supported and get selected through the route definition., (*5)

Requirements

Features / Goals

Main design goal of MxcRoutes is to encapsulate the controller child route definition via template defintions. So module programmers can setup the complete child route scheme for a controller be defining a single route., (*6)

1. Provide the capability to configure a controller routing models with a single route definition, (*7)

2. Allow to select among several child route models by name, (*8)

Set 'child_route_model' => 'myChildRouteModelName' in the defaults section of the MxcRoute., (*9)

3. Allow to extend child route models by inheritence, (*10)

Set 'extends' => 'myParentChildRouteName' within the child route model definition., (*11)

Installation

Main Setup

By cloning project

  1. Clone this project into your ./vendor/ directory.

With composer

  1. Add this project in your composer.json:, (*12)

    "require": {
        "mxc-commons/mxc-routes": "dev-master"
    }
    
  2. Now tell composer to download MxcRoutes by running the command:, (*13)

    $ php composer.phar update
    

Post installation

  1. Enabling it in your application.config.phpfile., (*14)

    <?php
    return array(
        'modules' => array(
            // ...
            'MxcRoutes',
        ),
        // ...
    );
    

Options

The MxcRoutes module provides a single option to setup and select child route schemes. After installing MxcRoutes, copy ./vendor/mxc-commons/mxc-routes/config/mxcroutes.global.php.dist to ./config/autoload/mxcroutes.global.php and setup the child route schemes as desired., (*15)

The following option is available:, (*16)

  • child_route_models - Array of child route models: <modelName> => array(<child_route>, ...), ... ), where modelNameis an identifier of your choice and each child_route is a ZF2 route definition.

See mxcroutes.global.php.dist for an example configuration including model inheritance., (*17)

Note: You can easily setup a child route scheme by copying and pasting an existing child route structure from your router configuration., (*18)

Note: Child route models may even contain nested child route definitions., (*19)

'may_terminate' => true,
'child_routes'  => array(
    ...
)

Setting an MxcRoute

You add an MxcRoute to your router configuration almost the same way as you add a Literal route. Just set the type key to 'mxc-route'., (*20)

                'album' => array(
                    'type' => 'mxc-route',
                    'options' => array(
                        'route' => '/album',
                        'defaults' => array(
                            'controller' => 'MxcMedia\Controller\Album',
                            'action' => 'list'
                        )
                    ),
                 ),

Using the configuration above MxcRoute will default to the child route model named default. You can select a particular child route model by specifying a child_route_model key within the 'defaults' section of the route definition., (*21)

                'album' => array(
                    'type' => 'mxc-route',
                    'options' => array(
                        'route' => '/album',
                        'defaults' => array(
                            'controller' => 'MxcMedia\Controller\Album',
                            'action' => 'list'
                            'child_route_model' => 'myChildRouteModelName'
                        )
                    ),
                 ),

Note: 'controller' and 'action' keys are mandatory, 'child_route_model' is optional., (*22)

How MxcRoutes works

  1. On Startup MxcRoutes registers a route plugin for the route type mxc-route with the RoutePluginManager
  2. Every time the router finds a route of type mxc-route the Router instantiates an MxcRoute to handle this route definition.
  3. The MxcRoute itself is derived from Zend\Mvc\Router\Http\Part route. It creates a literal for its own route definition, loads the child route model, sets the controller key in all child routes to the controller specified in the mxc-route.

Use Cases

Common use cases for MxcRoutes are, (*23)

  1. CRUD routing configurations

Credits

MxcRoutes was inspired by the CrudRoute implementation of SpiffyCrud by Kyle Spraggs. SpiffyCrud is a ZF2 module to allow rapid development of CRUD for entities., (*24)

License

MxcRoutes is released under the New BSD License. See license.txt., (*25)

The Versions

14/06 2016

dev-master

9999999-dev http://www.github.com/mxc-commons/MxcRoutes/

Zend Framework 2 Module that provides a new route to generate child route structures automatically according to a template configuration you provide.

  Sources   Download

BSD-3-Clause

The Requires

 

zf2 module