Zend_Form如何放<a> behind input text?</a>

时间:2012-03-21 17:09:17

标签: zend-framework zend-form

我尝试在输入文本后面添加一些HTML链接,我尝试这样做:

$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>之间放置一些东西?

最好的问候

1 个答案:

答案 0 :(得分: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
));

当然它是php5.3风格的回调,但你也可以使用oldstyle。