Is it a bug for Zend Framework's Zend_View?

105 views Asked by At

View Helpers have some initial helpers, such as formButton and formText.

As the reference said:

formText($name, $value, $attribs): Creates an <input type="text" /> element.

But I find something not like it on my PC. I write below code in a view file:

<?php 
echo $this->formText('email', '[email protected]', array('size' => 32));
?>

The HTML is as below:

<input type="text" name="email" id="email" value="[email protected]" size="32">

There isn't a '/' at the end.It should be :

<input type="text" name="email" id="email" value="[email protected]" size="32"/>

So is there something wrong? My version is ZF1.12 and PHP5.4.

2

There are 2 answers

0
danronmoon On

No. ZF checks whether the doctype you appended to the view is XHTML and adds the forward slash only if this is true.

Check out Zend_View_Helper_HtmlElement::getClosingBracket

if (!$this->_closingBracket) {
    if ($this->_isXhtml()) {
        $this->_closingBracket = ' />';
    } else {
        $this->_closingBracket = '>';
    }
}

return $this->_closingBracket;
0
Fouad Fodail On

It's not a bug. the output depends on your document's doctype. if it is an XHTML doctype it will output the /> otherwise it will output just the > to end the tag.

Check the Zend_View_Helper_FormText Class

....
// XHTML or HTML end tag?
    $endTag = ' />';
    if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
        $endTag= '>';
    }
....