0

我需要为现有控制器添加“addAction”和“ deleteAction ”。这里我使用了zendframework-ZendSkeletonApplication-zf-release-2.0.3,我在IndexController中添加了这两个动作,并且我为index文件夹中的每个动作创建了2个页面。但它如何添加到module.config.phpthis 是我的 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',
        ),
    ),
);

请帮我。

4

1 回答 1

2

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

'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具有 basePath/

之后,您有两个单独的子路由被调用add ,并且edit通过添加或编辑附加基本路径,因此它们的完整路由/add变为/edit

请考虑查看在线文档,以进一步澄清有关路由的问题,因为这确实是一个很好的起点。

或者,您可能还想查看ZendCon 的DASPRiDs Router Presentation

于 2012-10-30T07:01:57.267 回答