user2939345
user2939345

Reputation: 149

Zend framework 2 method routing

I would like to separate a form display and processing in the router config in Zend Framework 2 (v2.3.1):

        'login' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/login',
            ),
            'child_routes' => array(

                'show' => array(
                    'type' => 'method',
                    'options' => array(
                        'verb' => 'get',
                        'defaults' => array(
                            'controller' => 'Main',
                            'action' => 'loginShow'
                        ),
                    ),
                ),

                'process' => array(
                    'type' => 'method',
                    'options' => array(
                        'verb' => 'post',
                        'defaults' => array(
                            'controller' => 'Main',
                            'action' => 'loginProcess'
                        ),
                    ),
                ),

            ),
        ),

Somehow this doesn't work, i get the following error message:

Part route may not terminate

It would be great to use the same URL (route) but two different actions (depending on the request method) for displaying and processing the login form.

Thank you very much for your help!

M

Upvotes: 0

Views: 565

Answers (1)

rms230
rms230

Reputation: 24

You need to add may_terminate = true and that should solve your problems.

     'login' => array(
        'type' => 'Literal',
        'options' => array(
            'route' => '/login',
        ),
        'may_terminate' => true,
        'child_routes' => array(

            'show' => array(
                'type' => 'method',
                'options' => array(
                    'verb' => 'get',
                    'defaults' => array(
                        'controller' => 'Main',
                        'action' => 'loginShow'
                    ),
                ),
            ),

            'process' => array(
                'type' => 'method',
                'options' => array(
                    'verb' => 'post',
                    'defaults' => array(
                        'controller' => 'Main',
                        'action' => 'loginProcess'
                    ),
                ),
            ),

        ),
    ),

Upvotes: 1

Related Questions