ZF2 - Generating Url from route

做~自己de王妃 提交于 2019-12-04 02:40:29

Use the echo before calling $this->url(...) (see bellow) and this will display the whole URL.

<?php echo $this->url('route-name', $urlParams, $urlOptions); ?>

Note that the first paramter of url() is the name of the route as specified in your [module]/config/module.config.php file.

See this for more information about ZF2's URL view helper.

EDIT in response to the question edit:

The above section is related to using the URL view helper.

If you want a URL in the controller then you need the URL controller plugin.

<?php $url = $this->url()->fromRoute('route-name', $params, $options); ?>

This is the reference to the ZF2 manual for this controller plugin.

Hope this helps :)

Stoyan

Azhar Ahmad

You can use this in the .phtml file

echo $this->url('HelloWorld/default', array('controller'=>'Index', 'action'=>'registration'));

Where HelloWorld/default is the routing and the remaining is the controller and its action and also you can send the others parameter adding just in array as key and value pair.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!