【问题标题】:How to get URL string in ZF2 controller如何在 ZF2 控制器中获取 URL 字符串
【发布时间】:2015-05-15 10:09:53
【问题描述】:

我想要路由中控制器方法中的 URL。

$route = $this->url('my/route', array('id' => $myID), array(
                'force_canonical' => true,
                    ));

这会给我路由对象,但我想要的是像 URL

$link = "http://example.com/my/route/23" 

在变量中,因为我必须将其发送到其他操作以显示为文本。

【问题讨论】:

    标签: php zend-framework zend-framework2


    【解决方案1】:

    您可以通过这种方式从路由生成 URL:

    $params = array('id' => $myID);
    $url = $this->url()->fromRoute('my/route', $params);
    

    文档:(http://framework.zend.com/manual/current/en/modules/zend.mvc.plugins.html)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 2016-02-21
      相关资源
      最近更新 更多