1

我已经用ZF1开发了,现在我在玩ZF2。当您按照教程进行操作时,我已经在使用相册应用程序,并且一切正常。现在我想知道如何将新控制器添加到专辑模块。

我创建了一个名为 TestController 的新空控制器及其视图。为了测试它,我用新的 TestController 作为默认值更改了 module.config.php,它可以工作。在我再次更改为教程中的默认专辑控制器之​​后。好吧..问题出现在添加视图中,我从专辑中更改了这一行

<a href="<?php echo $this->url('test', array('action'=>'index'));?>">Test</a>

我在浏览器中点击了 www.testing.loc/add 但只渲染了一半的脚本而没有任何错误。

我的相册模块中的一些 module.config 如下所示:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',
            'Album\Controller\Test' => 'Album\Controller\TestController',

        ),
    ),
    'router' => array(
        'routes' => array(
            'album' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/',

                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Album\Controller\Album',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),    
    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

可能是视图中为 url 函数提供的参数的简单错误,但我用其他人证明了它是相同的。我从 ZF2 开始,但我不知道如何在同一个模块中使用多个控制器。非常欢迎任何建议。

4

1 回答 1

4

test您的配置中没有命名路由。语法是:

$this->url('ROUTENAME', $routeParams);

基本上你需要做的是改变路线:

'router' => array(
    'routes' => array(
        'test' => array(
            //copy the other parts
        )
    )
)

更多信息参见Zend\Mvc\Router -Documentation

于 2013-01-26T15:05:01.090 回答