ZF2 - 供应商模块ZFcUser的覆盖配置

时间:2013-08-16 15:12:15

标签: zend-framework2 zfcuser

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

这是更新后的代码。变化

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

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

---原帖---

我正在尝试从自定义模块(ContentManager)module.config.php中覆盖供应商模块(ZFcUser)的路由。 ContentManagerController扩展了原始UserController。我不想触摸ZFcUser的module.config.php,因为它可能会在通过composer进行预期更新后导致麻烦。我想严格分离我从原始供应商文件中所做的任何配置。 简单地覆盖

'route' => '/user',

'route' => '/cms',

目前有效,但不是我想要实现的目标。 所以,我还需要替换控制器条目

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

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

但这给了我404错误。

The requested controller was unable to dispatch the request.

Controller:
ContentManager\Controller\ContentManager

好像两个控制器都存在冲突。当我注释掉'defaults'数组时  然后按预期调用ZFcUser module.config.php我的ContentManagerController。 我还确保我的模块在ZFcUser之后注册。所以压倒一切应该有效,afaik。

我已经做了很多研究,但无法弄清楚这里发生了什么。 所描述的策略herethere不起作用。

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(
                    .
                    .
                    .
                ),
            ),
        ),
    ),
);

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

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

我只是自己找到了解决方案。由于我的ContentManagerController扩展了AbstractRestfulController,它自然没有实现索引操作。所以'行动'默认情况下的字段'数组必须被''重写。或者为null。然后将按预期调用取决于HTTP请求类型的正确操作。我在哪里?

这是更新后的代码。变化

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

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