I will show you how you can create simple but effective absolute
path view helper in Zend Framework. In this example, i will create new
file under /library/My/View/Helper with name GetApsolutePath.php
Download View Helper
Class My_View_Helper_GetAbsolutePath extends Zend_View_Helper_Abstract
{
public function getAbsolutePath() {
$server = Zend_Controller_Front::getInstance()->getRequest()->getServer();
$protocol = (!empty($server['HTTPS']) && $server['HTTPS'] !== 'off' || $server['SERVER_PORT'] == 443) ? "https" : "http";
$exp = explode("/", $protocol);
return strtolower(trim(array_shift($exp))) . '://' . $server['HTTP_HOST'];
}
}
That’s it! Now you can call your helper in your view scripts:<?php echo $this->getAbsolutePath(); ?>
By upper code example this will return http://www.codestance.com.Download View Helper
No comments:
Post a Comment