How to get baseUrl in ZF2 controller?
问题 In my zf2 controller I want to retrieve the application base URL (for example http://domain.com ). I tried the following call but it returns an empty string. $this->request->getBasePath(); How can I then get the http://domain.com part of URL in my controller? 回答1: I know this is not the prettiest way of doing it but, hey, it works: public function indexAction() { $uri = $this->getRequest()->getUri(); $scheme = $uri->getScheme(); $host = $uri->getHost(); $base = sprintf('%s://%s', $scheme,