views:

44

answers:

3

Some other frameworks have a link helper like output_link('anchor', 'destination'); to replace the need to type <a href=""></a> into the template. Does Zend have something similar? and do I have to declare the link in the action first before I can use it in the viewer?

+2  A: 

I am not sure if Zend has this, but all you would need to do is create your own outputLink in the View Helper (applications/views/helpers/) and set it up how you want to, should be pretty trivial.

class Zend_View_Helper_OutputLink extends Zend_View_Helper_Abstract
{
    public function outputLink($anchor, $description)
    {
        return '<a href="' . $anchor . '">' . $description . '</a>';
    }
}

Just modify it how you want to. And you would call it in your view like below:

<span><?php $this->outputLink('test.html', 'Test Me!'); ?> </span>
Brad F Jacobs
For outputting HTML tags is better to extend `Zend_View_Helper_HtmlElement` instead `Zend_View_Helper_Abstract`. It has nice methods for handling HTML attributes.
takeshin
I will take a look into that. Thanks.
Brad F Jacobs
+5  A: 

Zend_View_Helper_Url can generate URL in view, take a look on its API doc http://framework.zend.com/apidoc/core/Zend_View/Helper/Zend_View_Helper_Url.html

ngsiolei
A: 

No, you have to make one.

Maxence