ZendFramework autoRouting不起作用

时间:2013-03-29 07:29:35

标签: php zend-framework

// The following is a route to simplify getting started creating
            // new controllers and actions without needing to create a new
            // module. Simply drop new controllers in, and you can access them
            // using the path /application/:controller/:action
            '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(
                            ),
                        ),
                    ),
                ),
            ),

我用类TestController创建了一个TestController.php,有一个方法indexAction,但是如果我写/ application / index / test或/ application / index / index,我就无法使用这个路径执行它 - 全部好吧,但如果我将控制器更改为Test它不起作用,我的意思是/ application / test / test或/ application / test / index

1 个答案:

答案 0 :(得分:1)

不要忘记将新控制器添加到Application的module.config.php中的controllers ['invokables']配置部分:

'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController',
            'Application\Controller\Test' => 'Application\Controller\TestController',
        ),
    ),