issue with zend form element displaying
Please check the code below, the problem is that no form element are displayed in test action not able to locate
Test.php-->Form Class
class Application_Form_Test extends Zend_Form
{
public $T_FILEUP;
public $T_SUBMIT;
/*function init
* initialise all the elements
* */
public function _init()
{
$this->T_FILEUP=new Zend_Form_Element_Text('image');
//$this->T_FILEUP->setDestination(UPLOADS);
$this->T_SUBMIT=new Zend_Form_Element_Submit('add');
}
/*function to generate a form for specific function
* */
public function generateForm()
{
return $this->addElements(array($this->T_FILEUP,$this->T_SUBMIT));
}
}
TestAction
public function testAction()
{
$objForm=new Application_Form_Test();
开发者_JAVA技巧 $forms=$objForm->generateForm();
$this->view->form=$forms;
}
test.phtml
<?php
//echo $this->nm;
echo $this->form->image;
?>
The function name for the hook is wrong (no "_"):
use:
public function init()
{
$this->T_FILEUP=new Zend_Form_Element_Text('image');
//$this->T_FILEUP->setDestination(UPLOADS);
$this->T_SUBMIT=new Zend_Form_Element_Submit('add');
}
It is not generated because _init()
method is not exectuted. I believe that you wanted to use init()
rather that _init()
.
Just to clarify because I've had this same issue.
Bootstrap.php
_initXXXXX()
Controllers and Forms
init()
Subtle difference, but it will cause you to bang your head on a wall if you don't catch it.
精彩评论