2012-03-21 49 views
0

我试图把后面输入文本一些HTML链接,我尝试做它的财产以后这样的:Zend_Form如何把<a>放在输入文本后面?

$aElements[$iKey] = $oName = new Zend_Form_Element_Text($aValue['newsletter_question_answer_id']); 
$oName->addDecorator('HtmlTag', array(
         'tag' => 'a', 
         'href'=>'http://some_url.html', 
         'placement' => Zend_Form_Decorator_Abstract::APPEND 
        )); 

,我的问题是,我怎样才能把<a></a>之间的财产以后?

问候

+0

查看[AnyMarkup装饰器](http://www.zfsnippets.com/snippets/view/id/62)。 – 2012-03-22 03:04:48

回答

4

如果你不想写自己的装饰你必须使用回调:

$element->addDecorator('Callback', array(
    'callback' => function($content, $element, $options) { 
     Zend_Debug::dump($content, 'content'); //elements decorated so far 
     Zend_Debug::dump($element, 'element'); //current element 
     Zend_Debug::dump($options, 'options'); //other options 

     return "<a href=\"{$options['href']}\">{$options['label']}</a>"; 
    }, 
    'option' => 'value', //everything but 'callback' and 'placement' gets 
         //passed to callback as option 
    'href' => 'http://example.com', 
    'label' => 'Link!', 
    'placement' => Zend_Form_Decorator_Abstract::APPEND 
)); 

Ofcourse这是PHP5.3风格的回调,但您可以使用旧式了。

+0

非常感谢你,这是我需要的! :) – 2012-03-22 07:58:44

+0

http://stackoverflow.com/faq#howtoask - 有关于接受答案的段落 - 请做到这一点:]你和我将获得声望点 - http://stackoverflow.com/faq#reputation – vandalizmo 2012-03-22 10:23:40

+0

好的:)谢谢很多回答:) – 2012-03-22 10:28:30