简体   繁体   中英

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

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'
                    ),
                ),
            ),

        ),
    ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM