Unable to render Zend Form elements in ViewScript
I have Login.php form like this:
class Form_Login extends Zend_Form {
public function init() {
}
public function __construct(){
// Set method
$this->setMethod('post');
$elements = array();
$element = $this->createElement('text','username');
$element->setRequired(true);
$elements[] = $element;
$element = $this->createElement('password','password');
$element->setRequired(true);
$elements[] =开发者_运维技巧 $element;
$this->addElements( $elements );
$this->setDecorators( array( array( 'viewScript', array( 'viewScript' => '/authentication/login-form.phtml' ) ) ) );
}
}
/authentication/login-form.phtml
<table>
<tr>
<td><?= $this->getElement('username') ?></td>
</tr>
<tr>
<td><?= $this->getElement('password') ?></td>
</tr>
</table>
When I render the form thenI get following exception:
Message: Plugin by name 'GetElement' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;C:/wamp/www/databox/application/views\helpers/
Where I am going wrong. Should I enter any information in application.ini or Bootstrap.
Thanks
You need to pass the form to your view script to make it work.
public function someAction()
{
$this->view->form = new Form_Login();
}
in your view script you can receive the elements via
<table>
<tr>
<td><?= $this->form->getElement('username'); ?></td>
</tr>
<tr>
<td><?= $this->form->getElement('password'); ?></td>
</tr>
</table>
$this->setDecorators( array( array( 'viewScript', array( 'viewScript' =>'/authentication/login-form.phtml','form'=>$form ) ) ) );
and then in view
$this->form->getElement('elementName');
精彩评论