Zend_Navigation url 生成问题

发布于 2024-08-02 14:18:17 字数 1497 浏览 2 评论 0原文

我使用导航组件作为网站菜单。我还使用 let zend 从请求参数中找出所选的菜单项 - 我想这是自动完成的。唯一的问题是,要使其工作,必须在每个节点的导航配置中指定操作和控制器。这也意味着当 zend 从路由生成链接时,操作和控制器信息会自动附加到生成的链接中。

有人遇到同样的问题吗?

Zend 手册部分,解释Mvc导航页面功能。

示例:

引导程序中定义的一些路由:

 $router->addRoute('user_profile_tab', new Zend_Controller_Router_Route(
            'profil/:user/:location/:tab/*',
            array(
                'action'     => 'profile',
                'controller' => 'user',
                'user'      => ($user ? $user->id : 0), //change later
                'location'      => 0 //inject appropriate value later
            )
        ));

导航容器对象:

$container = .....
......,
array(
       'label' => tr('Privileges'),
        'id'    => 'user-profile-perms',
    'type' => 'Zulu_Navigation_Page',
    'controller' => 'user',
    'action' => 'profile',
    'route'=> 'user_profile_tab',
        'params' => array('tab'=>Main_Lib_Common::NAVI_USER_TAB_PERMS)
)
);

使用 WHY 操作和控制器参数时的结果

$page = $container->getById('user-profile-perms');
$page->href;

http://www.example.com/profil/1/0/3/controller/user/action/profile

在您询问的导航容器对象中 。 $page->isActive() 检查需要此数据才能完美匹配。

修复:

扩展 mvc 导航页面并提供替代的 getHref() 方法……当路由未定义操作、控制器和模块参数时,该方法会删除它们。

I use Navigation component for site menus. I also use let zend figure-out the selected menu item from request parameters - I guess this is done automatically. The only problem is, that for this to work, action and controller have to be specified in navigation configuration for every node. This also means that when zend generates links from route, action and controller information to appended to the generated link automatically.

Anyone had the same problem?

Zend manual section, explaining the Mvc navigation page features.

Example:

some route defined in bootstrap:

 $router->addRoute('user_profile_tab', new Zend_Controller_Router_Route(
            'profil/:user/:location/:tab/*',
            array(
                'action'     => 'profile',
                'controller' => 'user',
                'user'      => ($user ? $user->id : 0), //change later
                'location'      => 0 //inject appropriate value later
            )
        ));

navigation container object:

$container = .....
......,
array(
       'label' => tr('Privileges'),
        'id'    => 'user-profile-perms',
    'type' => 'Zulu_Navigation_Page',
    'controller' => 'user',
    'action' => 'profile',
    'route'=> 'user_profile_tab',
        'params' => array('tab'=>Main_Lib_Common::NAVI_USER_TAB_PERMS)
)
);

the result when using

$page = $container->getById('user-profile-perms');
$page->href;

http://www.example.com/profil/1/0/3/controller/user/action/profile

WHY action and controler params in the navigation container object you ask. The $page->isActive() check needs this data to make a perfect match.

THE FIX:

extend mvc navigation page and provide an alternative getHref() method ... one that removes action, controller and module params when a route does not define them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱殇璃 2024-08-09 14:18:17

我这样做是为了解决这个奇怪的行为:

  • 扩展 mvc 导航页面
  • 提供替代的 getHref() 方法
  • 检查路由,没有 action 、controller 和 module 参数,并在 href 生成之前从 params 数组中删除它们。

这样,isActive 匹配仍然有效,因为我们没有以任何方式修改路线或导航节点。

I have done this to fix this weird behaviour:

  • extend mvc navigation page
  • provide an alternative getHref() method
  • check for routes, not having action , controller and module parameters and remove them from params array before href generation.

This way the isActive matching will still work, as we didnt modify the route or navigation nodes in any way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文