如何在 ZF2 控制器中获取 URL 字符串
How to get URL string in ZF2 controller
我想URL在路由的控制器方法中。
$route = $this->url('my/route', array('id' => $myID), array(
'force_canonical' => true,
));
这会给我路由对象,但我想要的是 URL 就像
$link = "http://example.com/my/route/23"
在一个变量中,因为我必须将它发送到其他操作以显示为文本。
你可以通过这种方式从路由生成 URL :
$params = array('id' => $myID);
$url = $this->url()->fromRoute('my/route', $params);
文档:(http://framework.zend.com/manual/current/en/modules/zend.mvc.plugins.html)
我想URL在路由的控制器方法中。
$route = $this->url('my/route', array('id' => $myID), array(
'force_canonical' => true,
));
这会给我路由对象,但我想要的是 URL 就像
$link = "http://example.com/my/route/23"
在一个变量中,因为我必须将它发送到其他操作以显示为文本。
你可以通过这种方式从路由生成 URL :
$params = array('id' => $myID);
$url = $this->url()->fromRoute('my/route', $params);
文档:(http://framework.zend.com/manual/current/en/modules/zend.mvc.plugins.html)