【发布时间】:2011-06-23 05:26:05
【问题描述】:
我开始使用 zend 框架。我遇到了表单的这个问题。 在浏览器中打开 localhost/item/create 时,只显示 hello,不呈现表单。
我做了什么:
我用zf.sh create controller item 在我的项目中创建了一个控制器
然后zf.sh create action create item。
在库文件夹中,创建了 App->forms->ItemEditor.php
<?php
class App_forms_ItemEditor extends Zend_Form
{
public function __construct()
{
$email = $this->createElement('text', 'email');
$email->setLabel('Your email address:');
$email->setRequired(TRUE);
$email->addValidator(new Zend_Validate_EmailAddress());
$email->addFilters(array(
new Zend_Filter_StringTrim(),
new Zend_Filter_StringToLower()
));
$email->setAttrib('size', 40);
$this->addElement($email);
}
}
在 application.ini 文件中声明其命名空间
autoloaderNamespaces[] = "App_"
在views->scripts->item->create.phtml里面做了这个:
hello
<?php
echo $this->form->render();
?>
然后在 ItemController.php 中:
public function createAction()
{
$this->view->form=new App_forms_ItemEditor();
}
只有 hello 显示在浏览器中,其余的表单不显示。谁能指出我做错了什么。 谢谢
【问题讨论】:
-
您是否查看过 html 源代码(在您的浏览器中)?
标签: php oop model-view-controller zend-framework