Zend_Form how to put <a> behind input text?

末鹿安然 提交于 2019-12-25 03:36:19

问题


I try to put some HTML link behind input text and I try to do it's somthing like this:

$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
                    ));

and my question is how can I put somthing between <a> and </a> ?

Best Regards


回答1:


If You don't want to write Your own decorator You have to use callback:

$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 it's php5.3 style callback, but You can use oldstyle too.



来源:https://stackoverflow.com/questions/9809480/zend-form-how-to-put-a-behind-input-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!