0

我在实现下面在我的代码段中定义的多条路线时遇到问题

编辑:我也收到此异常 附加信息: Zend\Mvc\Exception\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 PS:我已经在 Account/Controller/Voucher 下有一个 Controller,在 Account/View/Voucher 下有一个名为index.phtml的视图现在我没有知道我在这里想念什么。

4

1 回答 1

1

正如上面的 Adnrew 和 Timdev 评论的那样,您的控制器中有一些不正确的地方,您可以检查控制器中的一些基本内容,您的以下代码是否正确。特别是错别字。

namespace Account\Controller;

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



class VoucherController extends AbstractActionController {

// you acctions


}
于 2013-06-13T13:13:40.133 回答