4

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!

4

1 回答 1

1

作者找到了解决方案,但没有回答问题(他对其进行了编辑),我只是将其复制粘贴到答案中。

我只是自己找到了解决方案。由于我的 ContentManagerController 扩展了 AbstractRestfulController 它自然没有实现索引操作。所以'defaults'数组中的'action'字段必须被''或null覆盖。然后将按预期调用取决于 HTTP 请求类型的正确操作。我的心在哪里?

这是更新的代码。改变

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

'defaults' => array(
    'controller' => 'ContentManager\Controller\ContentManager',
    'action'     => '', // or null
),
于 2014-04-29T19:50:13.167 回答