How to delete a route in ZF2?

I installed the following modules in my ZF2 application: ZfcUser , ZfCAdmin and ZfcUserlist . Although my problem is more general, I just want to clearly indicate what I'm trying to do.

zfcadmin-route /admin. zfcuser-route /user. ZfcUserlist modules come with a children's route for zfcuser, are named zfcuserlistand point to /user/list.

Instead, /user/listI want to call a list of users /admin/user. This, of course, is not a problem, I just registered a children's route for zfcadmin.

Now I want to remove the default route for the user list that comes with the module. So my question is: how can I cancel / delete a specific route in ZF2?

To clarify the situation, I have the following ways:

/admin
/admin/user   <- I added this one
/user/list    <- This comes shipped with the ZfcUserlist-module. I want to remove it

Any suggestions?

+4
source share
1 answer

To achieve what you want, you need this in Module.php:

namespace Foo;

use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;

class Module
{
    public function init(ModuleManager $moduleManager)
    {
        $events = $moduleManager->getEventManager();

        // Registering a listener at default priority, 1, which will trigger
        // after the ConfigListener merges config.
        $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'));
    }

    public function onMergeConfig(ModuleEvent $e)
    {
        $configListener = $e->getConfigListener();
        $config         = $configListener->getMergedConfig(false);

        // Modify the configuration; here, we'll remove a specific key:
        if (isset($config['router']['routes']['your_route'])) {
            unset($config['router']['routes']['your_route']);
        }

        // Pass the changed configuration back to the listener:
        $configListener->setMergedConfig($config);
    }
}

This is just an example. You need to change yout_routeto the part of the array that represents /user/list.

Source

+3
source

Source: https://habr.com/ru/post/1539230/


All Articles