Вопрос

I've installed the following modules into my ZF2-Application: ZfcUser, ZfCAdmin and ZfcUserlist. Though my problem is more general, I just want to make clear what I am trying to do.

The zfcadmin-route is /admin. The zfcuser-route is /user. The ZfcUserlist-modules is shipped with a child-route for zfcuser, is named zfcuserlist and points to /user/list.

Instead of /user/list I want to call the user list by /admin/user. That of course is no problem, I just registered a child-route for zfcadmin.

Now I want to remove the default route for the user list which is shipped with the module. So my question is: How can I unregister/remove a certain route within ZF2?

To clear things up, I've got the following paths:

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

Any suggestions?

Это было полезно?

Решение

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);
    }
}

It is just example. You need to change yout_route to that part of array, which represents /user/list.

Source

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top