ZF2: Zend Framework 2 Full URL including host name

后端 未结 4 798
一生所求
一生所求 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:54

    If you want to set base URL globally, you can do it using onBootstrap method:

    $e->getApplication()->getMvcEvent()->getRouter()->setBaseUrl($baseUrl);
    

    In this case Navigation helpers would also use it.

    To fetch current base URL use ServerUrl helper as described in this thread:

    $serverUrl = $e->getApplication()->getServiceManager()->get('ViewHelperManager')->get('ServerUrl');
    $baseUrl = $serverUrl->__invoke();
    

提交回复
热议问题