【问题标题】:ZF2 - Overriding Configuration of Vendor Module ZFcUserZF2 - 供应商模块 ZFcUser 的覆盖配置
【发布时间】:2013-08-16 15:12:15
【问题描述】:

编辑: 我只是自己找到了解决方案。 由于我的 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(
                    .
                    .
                    .
                ),
            ),
        ),
    ),
);

感谢您的帮助!

【问题讨论】:

    标签: zend-framework2 zfcuser


    【解决方案1】:

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

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

    这是更新后的代码。改变

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-22
      相关资源
      最近更新 更多