Disable default zfcUser routes?

2019-07-14 18:32发布

I'm using zfcUser and I was wondering if its possible to disable the default routes, such as zfcUser/login, zfcUser/register, etc because I do not want to expose them.

I looked at the zfcuser.global.php but there seems to be no such option?

Thanks

1条回答
闹够了就滚
2楼-- · 2019-07-14 18:46

You can simply override the configuration by setting a null controller or an unmatchable routing configuration.

Solution 1: override the zfcuser controller invokable:

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

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

Solution 2: overriding routing configuration by using your own route config (hacky, discouraged):

// 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,
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
);
查看更多
登录 后发表回答