gpt4 book ai didi

php - Zend 框架 2 : active menu items

转载 作者:可可西里 更新时间:2023-11-01 13:32:11 26 4
gpt4 key购买 nike

从配置构建导航:

'navigation' => array(
'default' => array(
'admin' => array(
'label' => 'Administration',
'controller' => 'index',
'action' => 'index',
'route' => 'admin/default',
),
'album' => array(
'label' => 'Album',
'controller' => 'index',
'action' => 'index',
'route' => 'album/default',
),
/* ... */

路由配置得像真的一样。菜单中的导航有效。链接菜单指向所需模块的所需 Controller /操作。但是,在引入菜单并过渡到一个或另一个菜单项时,active 会同时标记“管理”和“相册”这两个点。据我了解,由于 Controller 和 Action 的名称与它们相匹配,但仍然存在“路线”并且它是不同的......并非没有为每个项目生成不同的网址......但不知何故,尽管这样,它们都被标记为事件的。

路由配置:

    'router' => array(
'routes' => array(
'admin' => array(
'type' => 'Literal',
'options' => array(
'route' => '/admin',
'defaults' => array(
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller][/:action[/id:id]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
),
),
),

相册路由配置类似...

为什么会这样?谢谢。

最佳答案

看起来这就是 ZF2 的工作方式(阅读 Zend\Navigation\Page\Mvc.php 中的 isActive() 函数)。最初它检查路由/ Controller / Action 的匹配,但如果失败,ZF2 再次检查 Controller / Action 对。所以有以下三种可能的方式:

  1. https://github.com/zendframework/zf2/issues 开票并等待回应。

  2. 覆盖 \Zend\Navigation\Page\Mvc

  3. 为 Controller 选择不同的名称(不要使用 index 名称,因为它是 Mvc.php 中 Controller 的默认名称)。

关于php - Zend 框架 2 : active menu items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12910300/

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