$this->view->baseUrl() must work.
But I suggest creating a new action helper, which is basically a copy of the view helper, but you can change it to suit your needs:
class My_Controller_Action_Helper_BaseUrl
extends Zend_Controller_Action_Helper_Abstract
{
public function direct($file = null, $full = true)
{
return $this->baseUrl($file, $full);
}
protected $_baseUrl;
public function baseUrl($file = null)
{
$baseUrl = $this->getBaseUrl();
if (null !== $file) {
$file = '/' . ltrim($file, '/\\');
}
return $baseUrl . $file;
}
public function setBaseUrl($base)
{
$this->_baseUrl = rtrim($base, '/\\');
return $this;
}
public function getBaseUrl()
{
if ($this->_baseUrl === null) {
require_once 'Zend/Controller/Front.php';
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
$baseUrl = $this->_removeScriptName($baseUrl);
$this->setBaseUrl($baseUrl);
}
return $this->_baseUrl;
}
protected function _removeScriptName($url)
{
if (!isset($_SERVER['SCRIPT_NAME'])) {
return $url;
}
if (($pos = strripos($url, basename($_SERVER['SCRIPT_NAME']))) !== false) {
$url = substr($url, 0, $pos);
}
return $url;
}
}
source
share