简体   繁体   English

如何在ZF2控制器中获取URL字符串

[英]How to get URL string in ZF2 controller

I want URL in controller method from the route. 我想从路由的控制器方法中获取URL。

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

This will give me the route object but what I want is URL like 这将给我路由对象,但我想要的是URL

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

in a variable as I have to send it to other action for display as text. 在变量中,因为我必须将其发送到其他操作以显示为文本。

you can generate URL from route this way : 您可以通过以下方式从路由生成URL:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM