【问题标题】:While using Zend Router, other links (the ones that aren't defined as routes) corrupt使用 Zend Router 时,其他链接(未定义为路由的链接)损坏
【发布时间】:2012-12-24 12:06:31
【问题描述】:

我正在使用 Zend Framework 1.12。

我想添加一些路由器。我的系统中有用户和管理员,我添加了一个路由器供管理员查看用户页面。

我加了

// meant to create the usage "xxx.com/userview/someusername"
    $route = new Zend_Controller_Router_Route(
            'userview/:username',
            array('controller' => 'user',
                'action' => 'viewone',
                'username' => 'someusernamedefault')
            );
    $router = $frontController->getRouter();
    $router->addRoute('userview', $route);

到我的 Bootstrap.php 文件。 我的侧边栏中有一些链接,其中包含指向(另一个控制器的)操作的链接。我已将他们的链接添加到 .phtml 文件中作为

echo $this->url(array('controller'=>'somecontroller', 'action'=>'someaction' ), null, true);

此侧边栏包含许多此链接,这些链接来自多个控制器。

这些工作正常,直到我添加了路线。在我向 Bootstrap 添加新路由(并向从 rooter 指向的控制器(用户)添加新操作(viewall)后,效果很好(我可以用作“xxx.com/userview/someusername”)。但我的其他链接在侧边栏都变成了“xxx.com/userview”。他们都失去了控制器和动作的价值......

我做错了什么??我应该更好地定义我的 url,还是更好地定义我的路由器?

提前致谢。

【问题讨论】:

    标签: php zend-framework url-routing zend-route zend-router


    【解决方案1】:

    URL 助手的第二个参数应该是您要使用的路由的名称。通过传递 null 您告诉它使用当前路由,这就是链接出错的原因。将侧边栏链接调用更改为:

    $this->url(array('controller'=>'somecontroller', 'action'=>'someaction'), 'default');
    

    然后它应该可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 2022-01-21
      • 1970-01-01
      • 2013-08-21
      • 2020-10-02
      • 1970-01-01
      • 2019-01-21
      • 2020-11-03
      • 1970-01-01
      相关资源
      最近更新 更多