-- Marc Tempelmeier <[email protected]> wrote
(on Tuesday, 04 September 2012, 03:47 PM +0200):
> I have my ZF1 controllers devided in different modules. Now I want to
> port the whole stuff to ZF2.  Because I have a route which "rules them
> all" I want something like in ZF1.
> 
> Example:
> 
> /modulename/controller/action/key1/value1/key2/value2/...
> 
> But holy moses is that difficult to achieve with the current docs. I
> know that they are not complete, but I don´t think i´m the only one
> with that use case.
> 
> I read this:
> 
> http://packages.zendframework.com/docs/latest/manual/en/user-guide/routing-and-controllers.html
> 
> and the docs for the segmented route, but I can´t figure it out ;)
> 
> I think I have to put them in the module.config.php of the
> application, because of the "rule them all"-rule.
> 
> But how can I set the route?

We actually explicitly recommend this practice, as it makes it (a)
difficult to re-use modules, and (b) can introduce conflicts if you
install 3rd party modules -- something we're trying to encourage at this
time.

I *could* show you how to emulate the ZF1 module route in ZF2, but for
the reasons stated above, I won't; it's a bad idea.

Our recommendation is that you create at least one route per module,
with child routes, with the parent route representing the module. As an
example:

    'routes' => array(
        'module-name' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/something-representative-of-my-module',
                'defaults' => array(
                    '__NAMESPACE__' => 'MyModuleName\Controller',
                    'controller'    => 'IndexOrSomethingSemanticallyNamed',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/[:controller[/[:action[/]]]',
                    ),
                    'may_terminate' => true,
                    'child_routes' => array(
                        'wildcard' => array(
                            'type' => 'Wildcard',
                        ),
                    ),
                ),
            ),
        ),
    ),

What the above does is provide a literal route as the root for the
various controllers under that module. You set up a default controller
name, as well as the root namespace for controller aliases in that
module.

It has a child route. That route is a segment route that matches
controller and action, but does so conditionally, so that each of the
following work:

    /something-representative-of-my-module
    /something-representative-of-my-module/
    /something-representative-of-my-module/controller-name
    /something-representative-of-my-module/controller-name/
    /something-representative-of-my-module/controller-name/action-name
    /something-representative-of-my-module/controller-name/action-name/

That route also has a child route, a wildcard route. Because we provided
no configuration, you'll get the same behavior as in ZF1 -- key/param
pairs.

If you use the ZendSkeletonModule, a route similar to this is provided
in it, giving you a way to start developing your module quickly in a way
that will keep your module re-usable.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

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


Reply via email to