What I find strange is that 

/access/login defaults to /access/login/index
but 
/access/logout does NOT default to /access/logout/index

The same behavior I have in the application module with 2 controller.

There:

LoginController with indexAction
LogoutController with indexAction

Anyone an idea? :)

-----Ursprüngliche Nachricht-----
Von: Marc Tempelmeier 
Gesendet: Dienstag, 4. September 2012 16:57
An: '[email protected]'
Betreff: AW: [fw-general] Zf1-like routes

I hope you meant that you don´t recommend it ;)

The reasons behind that are understandable!

I set up this route now in my module as an example:

return array(
    'controllers' => array(
        'invokables' => array(
            'Access\Controller\Login' => 'Access\Controller\LoginController',
            'Access\Controller\Logout' =>'Access\Controller\LogoutController'
        ),
    ),
    'router' => array(
        'routes' => array(
            'access' => array(
                'type' => 'Literal',
                'options' => array(
                    'route' => '/access',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Access\Controller',
                        'controller'    => 'login',
                        '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',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

I hope I interpreted your line 'route' => '/[:controller[/[:action[/]]]', 
correctly, because u had more opening then closing [. 

Matches are now:

/access/login/index
/access/logout/index

but not:

/access/logout/lala

What I find strange is that 
/access/login defaults to /access/login/index
but 
/access/logout does NOT defaults to /access/logout/index

Why? 



-----Ursprüngliche Nachricht-----
Von: Matthew Weier O'Phinney [mailto:[email protected]] 
Gesendet: Dienstag, 4. September 2012 16:19
An: [email protected]
Betreff: Re: [fw-general] Zf1-like routes

-- 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]



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


Reply via email to