2013-03-19 134 views
2

我使用zfcUser,我想知道是否可以禁用默认路由,如zfcUser/login,zfcUser/register等,因为我不想公开它们。禁用默认zfcUser路由?

我看着zfcuser.global.php但似乎没有这样的选择?

感谢

回答

3

你可以简单地通过设置一个空控制器或无可比拟的路由配置覆盖配置。

解决方案1:覆盖zfcuser控制器可调用:

// YourApp\Module#getConfig() or config/autoload/zfcuser.override.global.php 

return array(
    'controllers' => array(
     'invokables' => array(
      'zfcuser' => null, 
     ), 
    ), 
); 

解决方案2:重写使用自己的路由配置(哈克,气馁)路由配置:

// YourApp\Module#getConfig() or config/autoload/zfcuser.override.global.php 

return array(
    'router' => array(
     'routes' => array(
      'zfcuser' => array(
       // changing to hostname route - using an unreachable hostname 
       'type' => 'Hostname', 
       // minimum possible priority - all other routes come first. 
       'priority' => ~PHP_INT_MAX, 
       'options' => array(
        // foo.bar does not exist - never matched 
        'route' => 'foo.bar', 
        'defaults' => array(
         'controller' => null, 
         'action' => 'index', 
        ), 
       ), 

       // optional - just if you want to override single child routes: 
       'child_routes' => array(
        'login' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
        'authenticate' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
        'logout' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
        'register' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
        'changepassword' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
        'changeemail' => array(
         'options' => array(
          'defaults' => array(
           'controller' => null, 
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
); 
+0

这似乎你的答案被缩短了;你可以再次发布NullRoute建议吗? – KaiserJohaan 2013-03-19 09:19:21

+0

@KaiserJohaan'NullRoute'建议实际上太方便了。我决定拆除它,因为它很长,与上面提到的解决方案相比,它没有任何好处。 – Ocramius 2013-03-19 09:22:35

+0

仅供参考,第一种解决方案应该没问题,因为它基本上完全取消了'zfcuser'控制器,这也是安全的。 – Ocramius 2013-03-19 09:23:45