按钮中的zend2图标

时间:2015-05-09 08:17:34

标签: php zend-framework2 icons

我找到了很好的解决方案,但不幸的是Zend2返回错误

溶液: Button content in ZF2 forms

错误:

  

Zend \ View \ HelperPluginManager :: createFromInvokable:检索失败   “formbutton(别名:formbutton)”通过invokable类   “MyModule的\表格\查看\助手\ FormButton”;类不存在

在MyModule \ Form \ View \ Helper \ FormButton中我创建了FormButton.php:

use Zend\Form\View\Helper\FormButton as ZendFormButton;
class FormButton extends ZendFormButton
{    
    public function render(ElementInterface $element, $buttonContent = null)
    {
        $content = (isset($buttonContent)) ? $buttonContent : $element->getLabel();
        $icon    = isset($element->getOption('icon')) ? $element->getOption('icon') : '';

        $escape = $this->getEscapeHtmlHelper();

        return $this->openTag($element).$icon.$escape($content).$this->closeTag();
    }   
}

和Module.php:

public function getViewHelperConfig()
    {
        return array(
            'invokables' => array(
                'form_button' => 'MyModule\Form\View\Helper\FormButton',
            )
        );
    }
在ProductForm.php中

$this->add(array(
    'type' => 'Button',
    'name' => 'submit',
    'options' => array(
        'label'   => 'Modifica',
        'icon'    => '<i class="icon icon-foo">',
    ),
    'attributes' => array(
        'type'  => 'submit',
        'class' => 'btn btn-warning'
    )
));

1 个答案:

答案 0 :(得分:0)

希望这会对你有所帮助。将disable_html_escape标记值用作true

$this->form->add(array(
     'type' => 'Zend\Form\Element\Checkbox',
     'name' => 'agreement_point',
     'options' => array(
         'label' => $this->getTranslatorHelper()->translate('Ich akzeptiere die <a class="first-agreement">Allgemeinen Geschäftsbedingunge</a>, die <a class="second-agreement">Wiederrufsbedingungen</a> und'),
            'label_options' => array(
            'disable_html_escape' => true,
        ),
     )
));