noobie-php
noobie-php

Reputation: 7213

Multiple routes under same tree in ZF2

I am having problem while implementing Multiple routes as defined Below in my snippet

EDIT: i am getting this exception too Additional information: Zend\Mvc\Exception\InvalidControllerException

with Message

Controller of type Account\Controller\VoucherController is invalid; must implement 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',
        ),
    ),
),
);

Now the issue is i am getting a 404, when i try to access MyHost/account/Voucher P.S: I already have A Controller under Account/Controller/Voucher and a view under Account/View/Voucher named as index.phtml now i dont know what am i missing here.

Upvotes: 0

Views: 433

Answers (1)

Developer
Developer

Reputation: 26173

As Adnrew and Timdev comments above that there is something not right in your controller, you can check few basic things in your controller, that you have following code correct. specially the typos.

namespace Account\Controller;

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



class VoucherController extends AbstractActionController {

// you acctions


}

Upvotes: 1

Related Questions