Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取包含在<;中的表单元素标签;标签>;标签_Php_Zend Framework_Label_Zend Form - Fatal编程技术网

Php 如何获取包含在<;中的表单元素标签;标签>;标签

Php 如何获取包含在<;中的表单元素标签;标签>;标签,php,zend-framework,label,zend-form,Php,Zend Framework,Label,Zend Form,我正在Zend表单中创建复选框元素,如下所示: $element = $this->CreateElement('checkbox', 'CheckIt'); $element->setLabel('Check It'); $elements[] = $element; echo $this->element->getElement("CheckIt")->getLabel(); 当我得到这样的标签: $element = $this->CreateEle

我正在Zend表单中创建复选框元素,如下所示:

$element = $this->CreateElement('checkbox', 'CheckIt');
$element->setLabel('Check It');
$elements[] = $element;
echo $this->element->getElement("CheckIt")->getLabel();
当我得到这样的标签:

$element = $this->CreateElement('checkbox', 'CheckIt');
$element->setLabel('Check It');
$elements[] = $element;
echo $this->element->getElement("CheckIt")->getLabel();
它输出:

Check It
但我想要以下输出:

<label for='CheckIt'>Check It</label>
检查一下
getLabel()函数中是否有任何选项,或者是否有任何其他函数可以实现这一点


谢谢

我很惊讶,虽然装饰师学习和理解起来很枯燥,但一旦你理解了他们,他们就有用了

这是我的课程之一,你可以很容易地添加它来满足你的需要

<?php
class My_Label extends Zend_Form_Decorator_Abstract
{
    protected $_format = '<td class="nome_campo"><label for="%s">%s%s</label></td>';

    public function render($content)
    {
        $element = $this->getElement();

        $id      = htmlentities($element->getId(), ENT_QUOTES, "UTF-8");
        $label   = htmlentities($element->getLabel(), ENT_QUOTES, "UTF-8");
        if ($element->isRequired())
            $asterisk = '<span class="required">*</span> ';
        else
            $asterisk = '';

        $markup = sprintf($this->_format, $id, $asterisk, $label);


        //per avere valid xhtml/html
        if (stripos($element->getType(), 'radio') !== false )//Zend_Form_Element_Radio
        {
            $this->_format = '<td class="nome_campo">%s%s</td>';
            $markup = sprintf($this->_format, $asterisk, $label);
        }


        $placement = $this->getPlacement();
        $separator = $this->getSeparator();
        switch ($placement) {
            case self::APPEND:
                return $content . $separator . $markup;
            case self::PREPEND:
            default:
                return $markup . $separator . $content;
        }
    }
}

我很惊讶,虽然装饰师学习和理解起来很无聊,但一旦你理解了他们,他们就会有用

这是我的课程之一,你可以很容易地添加它来满足你的需要

<?php
class My_Label extends Zend_Form_Decorator_Abstract
{
    protected $_format = '<td class="nome_campo"><label for="%s">%s%s</label></td>';

    public function render($content)
    {
        $element = $this->getElement();

        $id      = htmlentities($element->getId(), ENT_QUOTES, "UTF-8");
        $label   = htmlentities($element->getLabel(), ENT_QUOTES, "UTF-8");
        if ($element->isRequired())
            $asterisk = '<span class="required">*</span> ';
        else
            $asterisk = '';

        $markup = sprintf($this->_format, $id, $asterisk, $label);


        //per avere valid xhtml/html
        if (stripos($element->getType(), 'radio') !== false )//Zend_Form_Element_Radio
        {
            $this->_format = '<td class="nome_campo">%s%s</td>';
            $markup = sprintf($this->_format, $asterisk, $label);
        }


        $placement = $this->getPlacement();
        $separator = $this->getSeparator();
        switch ($placement) {
            case self::APPEND:
                return $content . $separator . $markup;
            case self::PREPEND:
            default:
                return $markup . $separator . $content;
        }
    }
}

在你的问题中有一个概念上的误解:
getLabel()
是对象属性的一个简单getter方法

$element; // is a Zend_Element object
$label = $element->getLabel(); // returns the value of the label property and not a HTML string
如果需要HTML输出,必须对对象调用
render()
,但这将呈现整个表单,而不仅仅是标签值。您可以禁用元素的装饰器,但在呈现表单本身时,您必须再次启用它们

另外,你的问题中有一个正式的错误。要么是

$element->getLabel();
// or once you have added the element to the form
$this->getElement('CheckIt')->getLabel();

您的问题在概念上存在误解:
getLabel()
是对象属性的简单getter方法

$element; // is a Zend_Element object
$label = $element->getLabel(); // returns the value of the label property and not a HTML string
如果需要HTML输出,必须对对象调用
render()
,但这将呈现整个表单,而不仅仅是标签值。您可以禁用元素的装饰器,但在呈现表单本身时,您必须再次启用它们

另外,你的问题中有一个正式的错误。要么是

$element->getLabel();
// or once you have added the element to the form
$this->getElement('CheckIt')->getLabel();
renderLabel()


渲染该标签

renderLabel()



呈现那个标签

不,你必须构建自己的标签,这可能会比你写这个问题花费更少的时间。或者也许你的行为是你需要定制的装饰器或视图脚本?@max4ever:是的。。我要求的解决方案比写这个问题花费的时间要少。我不熟悉装修工。谢谢..不,你必须建立你自己的,写这个问题可能比你写这个问题花费的时间要少。或者也许你的行为是你需要定制的装饰器或视图脚本?@max4ever:是的。。我要求的解决方案比写这个问题花费的时间要少。我不熟悉装修工。谢谢..+1我会倒霉的,他们为特定的装饰超载。在默认情况下,它将它包装在
dt
元素中,不过@adrian这也有一个秘密!对于每个元素,添加此调用以除去所有不需要的装饰器:$element->setDecorators(数组('ViewHelper','Label','Errors');注意,只需调用$element->removeDecorator('DtDdWrapper');是不够的+1我会被诅咒,他们超载的具体装饰。在默认情况下,它将它包装在
dt
元素中,不过@adrian这也有一个秘密!对于每个元素,添加此调用以除去所有不需要的装饰器:$element->setDecorators(数组('ViewHelper','Label','Errors');注意,只需调用$element->removeDecorator('DtDdWrapper');这还不够