ZF2中同一树下的多条路由

时间:2013-06-12 20:47:54

标签: php zend-framework2

我在我的代码段

中实现下面定义的多个路由时遇到问题 编辑:我也得到了这个例外 其他信息: 的Zend \的mvc \异常\ InvalidControllerException

带消息

Account \ Controller \ VoucherController类型的控制器无效;必须实现Zend \ Stdlib \ DispatchableInterface

<?php
namespace Account;
 return array(
'controllers' => array(
    'invokables' => array(
        'Account\Controller\Account' => 'Account\Controller\AccountController',
        'Account\Controller\Voucher' => 'Account\Controller\VoucherController',
    ),
    // --------- Doctrine Settings For the Module
    'doctrine' => array(
        'driver' => array(
            'account_entities' => array(
                'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
                'cache' => 'array',
                'paths' => array(__DIR__ . '/../src/Account/Entity')
            ),
            'orm_default' => array(
                'drivers' => array(
                    'Account\Entity' => 'account_entities'
                )
            )
        )
    ),
    // The following section is new and should be added to your file
    'router' => array(
        'routes' => array(
            'account' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/account[/][:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Account\Controller\Account',
                        'action' => 'index',
                    ),
                ),
            ),
            'voucher' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/account/voucher[/][:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Account\Controller\Voucher',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'account' => __DIR__ . '/../view',
        ),
    ),
),
);

现在我的问题是,当我尝试访问 MyHost / account / Voucher 时,我会收到404 P.S:我已经在账户/控制器/凭证下有一个控制器,账户/视图/凭证下的视图名为 index.phtml 现在我不知道我在这里缺少什么。

1 个答案:

答案 0 :(得分:1)

正如Adnrew和Timdev在上面评论说你的控制器中有一些不正确的东西,你可以检查控制器中的一些基本内容,你有正确的代码。特别是错别字。

namespace Account\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;



class VoucherController extends AbstractActionController {

// you acctions


}