1
在projectfolder /應用/表格創建的表單/ login.php中表單元素未顯示?
class Form_Login extends Zend_Form {
public function _construct() {
$this->setMethod('post');
$elements = array();
$element = $this->addElement('text', 'username');
$element->setLabel('Username');
$elements[] = $element;
$element = $this->addElement('password', 'password');
$element->setLabel('Password');
$elements[] = $element;
$this->addElements($elements);
$this->setElementDecorators(array('ViewHelper'));
}
}
在的myproject /應用/控制器訪問表單/ AuthenticationController.php
public function loginAction() {
$this->view->heading = 'Login';
$this->view->form = new Form_Login();
}
在login.phtml
<h1><?= $this->heading; ?></h1>
<?= $this->form; ?>
問題:
顯示標題但不顯示任何表單元素。我在這裏做錯了什麼?
感謝
是的,你是正確的,但現在它繼續並生成另一個錯誤:'致命錯誤:未捕獲異常'Zend_Controller_Response_Exception'帶消息'無法發送標題S;頭文件已經發送到/var/www/student/application/Bootstrap.php,第28行在/var/www/student/library/Zend/Controller/Response/Abstract.php:321' – Student 2011-05-15 07:31:01
好的。我在** Bootstrap.php **中刪除了'?>'(php結束標記)後的多餘空格,並且刪除了上面的錯誤。現在錯誤是'消息:方法setLabel不存在'.... – Student 2011-05-15 07:38:36
使用$ this-> addElement('text','username',array('label'=>'Username')); – 2011-05-15 07:41:06