ZF2 - Overriding Configuration of Vendor Module ZFcUser

1.1k Views Asked by At

EDIT: I just found the solution on my own. As my ContentManagerController extends AbstractRestfulController it naturally has no index action implemented. So the 'action' field in the 'defaults' array has to be overridden by '' or null. Then the proper action depending on the HTTP request type will be invoked as expected. Where was my mind?

Here's the updated code. Change

'defaults' => array(
    'controller' => 'zfcuser',
    'action'     => 'index',
),

to

'defaults' => array(
    'controller' => 'ContentManager\Controller\ContentManager',
    'action'     => '', // or null
),

--- Original Post ---

I'm trying to override the routes of a vendor module (ZFcUser) from within a custom module's (ContentManager) module.config.php. The ContentManagerController extends the original UserController. I don't want to touch the ZFcUser's module.config.php, as it could lead into troubles after a prospective update via composer. I want to strictly seperate any configurations made by me from the original vendor files. Simply overriding

'route' => '/user',

to

'route' => '/cms',

works for now, but isn't what I want to achieve. So, I need to replace the controller entry as well

'defaults' => array(
    'controller' => 'zfcuser',
    'action'     => 'index',
),

with

'defaults' => array(
    'controller' => 'ContentManager\Controller\ContentManager',
),

But that gives me a 404 error.

The requested controller was unable to dispatch the request.

Controller:
ContentManager\Controller\ContentManager

Seems as if both controllers are in conflict. When I comment out the 'defaults' array in the ZFcUser module.config.php my ContentManagerController is then invoked as expected. I also made sure that my module is registered after the ZFcUser. So overriding should work, afaik.

I did a lot of research already but can't figure out what's going on here. The strategies described here and there don't do the trick.

return array(
    'controllers' => array(
        'invokables' => array(
            'ContentManager\Controller\ContentManager' => 'ContentManager\Controller\ContentManagerController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'zfcuser' => array(
                'type' => 'Literal',
                'priority' => 1000,
                'options' => array(
                    'route' => '/cms',
                    'defaults' => array(
                        'controller' => 'ContentManager\Controller\ContentManager',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    .
                    .
                    .
                ),
            ),
        ),
    ),
);

Thanks for your help!

1

There are 1 best solutions below

0
On

Author found the soulution, but didn't answer the question (he edit it), I am just copy-pasting it to the answer.

I just found the solution on my own. As my ContentManagerController extends AbstractRestfulController it naturally has no index action implemented. So the 'action' field in the 'defaults' array has to be overridden by '' or null. Then the proper action depending on the HTTP request type will be invoked as expected. Where was my mind?

Here's the updated code. Change

'defaults' => array(
    'controller' => 'zfcuser',
    'action'     => 'index',
),

to

'defaults' => array(
    'controller' => 'ContentManager\Controller\ContentManager',
    'action'     => '', // or null
),