2013-08-16 50 views
4

编辑: 我刚刚找到了我自己的解决方案。 因为我的ContentManagerController扩展了AbstractRestfulController,所以它自然没有实现索引操作。所以'defaults'数组中的'action'字段必须被''或null覆盖。然后根据HTTP请求类型执行正确的操作将按预期调用。我的头脑在哪里?ZF2 - 供应商模块的首要配置ZFcUser

这是更新的代码。更改

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

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

---原贴---

我试图从一个自定义模块(ContentManager内覆盖供应商模块(ZFcUser)的航线)module.config.php。 ContentManagerController扩展了原来的UserController。我不想触摸ZFcUser的module.config.php,因为它可能会在通过作曲家进行预期更新后导致麻烦。我想严格分离我从原始供应商文件中所做的任何配置。 只需重写

'route' => '/user', 

'route' => '/cms', 

作品了,但不是我想要达到的目标。 所以,我需要

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

更换控制器项以及

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

但是,这给了我一个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

作者发现了这种营养,但没有回答这个问题(他编辑它),我只是将它复制粘贴到答案上。

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

这是更新的代码。更改

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

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