I use zend framework to develop my project. I want to get base url with its protocol in some model. I try following lines to do that. But it return empty.
$front = Zend_Controller_Front::getInstance();
$baseUrl = $front->getBaseUrl();
echo $baseUrl;
Can i get base url from that way. What are the best solution to do that. I can use also following line.
$baseUrl = 'http://'. $_SERVER['HTTP_HOST'];
echo $baseUrl;
But i want best solution. Please help me.
To get scheme and domain you can use this:
$request = Zend_Controller_Front::getInstance()->getRequest();
$url = $request->getScheme() . '://' . $request->getHttpHost();
The remaining part of url you can generate like this:
$serverUrlHelper = new Zend_View_Helper_ServerUrl();
$yourUrl = $serverUrlHelper->serverUrl(
$this->getHelper('url')->url(
array(
'module' => 'yourmodule',
'controller' => 'yourcontroller',
'action' => 'youraction',
),
null, // the route
true));