ZF2: Zend Framework 2 Full URL including host name

后端 未结 4 851
一生所求
一生所求 2021-02-02 00:32

In my view I need to draw full URL. Like this:

http://hostename.com/default/url

When I try to use $this->url(\'default\', array(1,2,3)

4条回答
  •  半阙折子戏
    2021-02-02 00:32

    I found this article with some interesting ways:

    1) without parameters use an empty array:

    // Using a route with the name "register" and the route "/register"
    echo $this->url('register', array(), array('force_canonical' => true)); 
    // Output: http://mydomain.com/register
    

    2) note the differences between:

    echo $this->serverUrl(); 
    // Output: http://mydomain.com
    

    and

    // Current URL: http://mydomain.com/register
    echo $this->serverUrl(true); 
    // Output: http://mydomain.com/register
    

    3) starting from the route

    // The "register" route has the following route: /register
    echo $this->serverUrl($this->url('register')); 
    // Output: http://mydomain.com/register
    

提交回复
热议问题