Change website

From Jan 16 2015,


All post content will be move to we's offical website with many content...

Can access website here: http://justox.com

Thanks for your visit!

Wednesday, 18 December 2013

Zend Framework Get Absolute Path View Helper

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



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