我已经在ZF2-Application中安装了以下模块:ZfcUser,ZfCAdmin和ZfcUserlist.虽然我的问题比较笼统,但我只想弄清楚我想要做什么.
zfcadmin-route是/ admin. zfcuser路由是/ user. ZfcUserlist-modules附带了zfcuser的子路由,名为zfcuserlist,并指向/ user / list.
而不是/ user / list我想通过/ admin / user调用用户列表.那当然没问题,我刚为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的数组部分.