gpt4 book ai didi

php - 如何删除 ZF2 中的路线?

转载 作者:可可西里 更新时间:2023-10-31 23:20:30 26 4
gpt4 key购买 nike

我已将以下模块安装到我的 ZF2 应用程序中:ZfcUser , ZfCAdminZfcUserlist .虽然我的问题比较笼统,但我只是想弄清楚我想做什么。

zfcadmin-路由是/adminzfcuser-路由是 /user。 ZfcUserlist 模块随 zfcuser 的子路由一起提供,名为 zfcuserlist 并指向 /user/list

我想通过/admin/user 调用用户列表,而不是/user/list。那当然没问题,我只是为 zfcadmin 注册了一个子路由。

现在我想删除模块附带的用户列表的默认路由。所以我的问题是:如何取消注册/删除 ZF2 中的特定路由?

为了解决问题,我有以下路径:

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

有什么建议吗?

最佳答案

要实现你想要的,你需要在 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);
}
}

这只是一个例子。您需要将 yout_route 更改为数组的那部分,它代表 /user/list

Source

关于php - 如何删除 ZF2 中的路线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23466811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com