Php 如何在zend2中向同一控制器添加多个操作

Php 如何在zend2中向同一控制器添加多个操作,php,zend-framework2,Php,Zend Framework2,我需要为现有控制器添加“addAction”和“deleteAction”。在这里,我使用了zendframework-ZendskeletonApp-zf-release-2.0.3,我在IndexController中添加了这两个操作,并且在索引文件夹中为每个操作创建了两个页面。但是它如何添加到module.config.php这是我的module.config.php文件的代码 <?php return array( 'router' => array(

我需要为现有控制器添加“addAction”和“deleteAction”。在这里,我使用了zendframework-ZendskeletonApp-zf-release-2.0.3,我在IndexController中添加了这两个操作,并且在
索引
文件夹中为每个操作创建了两个页面。但是它如何添加到
module.config.php
这是我的module.config.php文件的代码

<?php

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/application',
                    '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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController'
        ),
    ),
    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);

这是我在项目中使用的一个示例路由配置,其中所有内容都基于根路径
/

'router' => array(
    'routes' => array(
        'kz' => array(
            'type'    => 'literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Kennzahlen\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'add' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => 'add',
                        'defaults' => array(
                            'action' => 'add'
                        )
                    )
                ),
                'edit' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => 'edit',
                        'defaults' => array(
                            'action' => 'edit'
                        )
                    )
                )
            )
        ),
    ),
),
名为
kz
的第一条路由具有基本路径
/

'router' => array(
    'routes' => array(
        'kz' => array(
            'type'    => 'literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Kennzahlen\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'add' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => 'add',
                        'defaults' => array(
                            'action' => 'add'
                        )
                    )
                ),
                'edit' => array(
                    'type' => 'literal',
                    'options' => array(
                        'route' => 'edit',
                        'defaults' => array(
                            'action' => 'edit'
                        )
                    )
                )
            )
        ),
    ),
),
在此之后,您有两个单独的子路由,分别称为
add
edit
,它们用add或edit附加基本路径,因此它们的完整路由变为
/add
/edit

请考虑进一步检查关于路由的问题,因为这确实是一个很好的开始。
或者,您可能还想从ZendCon签出

您是否可以向上面的
module.config.php
添加另一条路由?请您向我展示@davidweinraubac,实际上我添加了另外两条路由,在这之后只添加最后一条路由@有时,路线的顺序很重要。我认为您需要将它们从最具体的(例如:
/somecontroller/:id/edit
/somecontroller/:id/delete
)添加到最不具体的(例如:
somecontroller/:id
)@Sam's在处理这方面做得很好。