Wednesday, October 03, 2007

Try Zend Framework vol.5 "Always absolute url"

Zend Framework has some cute View Helpers.
One of them is Zend_View_Helper_Url which generates url easily.
But, it gives part of url. Sometimes I want to get absolute path. :<
Don't you want? :>

library/Hoge/View/Helper/Url.php
<?php
require_once 'Zend/View/Helper/Url.php';

class Hoge_View_Helper_Url extends Zend_View_Helper_Url
{

public function url(array $urlOptions = array(), $name = null, $reset = false)
{
$server = Zend_Controller_Front::getInstance()->getRequest()->getServer();
$url = parent::url($urlOptions, $name, $reset);

return strtolower(trim(array_shift(split('/', $server['SERVER_PROTOCOL'])))) . '://' . $server['HTTP_HOST'] . $url;
}

}


To use it. Nothing changes from default usage.

application/views/scripts/hoge/url.phtml

<?= $this->url() ?>


I strongly inspired by this entry. So I could write the code above. :p
(weight 86.8kg BMI 29%)

Labels:

2 Comments:

At 2:44 AM, Blogger Unknown said...

yep, i want that thanks. Zend lacks at some standard stuff.

 
At 1:13 AM, Blogger esion said...

Okay I though I missed something. Thx!

Well, laughing code french translation (thanks to google) :
"fonction publique url() { ... }"

Oô something wrong, isn't it?!

KTHXBYE

 

Post a Comment

<< Home