Hi again,

when I work through the user guide of the manual I noticed the different
ways of handling the routing.

In the /module/Application/config/module.config.php there are two routes
defined:

-----------------------------------------------------------------
'home' => array(
    'type' => 'Zend\Mvc\Router\Http\Literal',
    'options' => array(
        'route'    => '/',
        'defaults' => array(
            'controller' => 'Application\Controller\Index',
            'action'     => 'index',
        ),
    ),
),
'application' => array(
    'type'    => 'Literal',
    'options' => array(
        'route'    => '/application',
        'defaults' => array(
            '__NAMESPACE__' => 'Application\Controller',
            'controller'    => 'Index',
            'action'        => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'default' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/[:controller[/:action]]',
                'constraints' => array(
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
                'defaults' => array(
                ),
            ),
        ),
    ),
),
-----------------------------------------------------------------

After creating my Album module I have another route:

-----------------------------------------------------------------
'album' => array(
    'type'    => 'segment',
    'options' => array(
        'route'    => '/album[/:action][/:id]',
        'constraints' => array(
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'     => '[0-9]+',
        ),
        'defaults' => array(
            'controller' => 'Album\Controller\Album',
            'action'     => 'index',
        ),
    ),
),
-----------------------------------------------------------------

Within ZF1 I really liked the convention to have the One Route to rule
them all.

I would like to do the same for my ZF2 application but have some
problems with it. A rule should look like this

/lang/module/controller/action/id/*

First is the language, followed by the module, the controller, the
action and an id. At the end I would other optional parameters to be
addable. The route should have some reasonable defaults and alle
segments should be optional. The reason for this is, that I don't want
to think about the routing any more for each module once I set the
standard route.

I tried aroud a little and thought that this might work, but it doesn't
even match a route with only a language in it.

-----------------------------------------------------------------
'application' => array(
    'type'    => 'Segment',
    'options' => array(
        'route'    => '[/:lang][/:module][/:controller][/:action]
                       [/:id]',
        'defaults' => array(
            'lang'          => 'de',
            'module'        => 'Application',
            'controller'    => 'Index',
            'action'        => 'index',
        ),
        'constraints' => array(
            'lang'       => '[a-z]{2}',
            'module'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id'         => '[0-9]+',
        ),
    ),
),
-----------------------------------------------------------------

Any ideas?

Best regards,

Ralf

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to