Zend Framework:在废话中找不到 Form_MyForm...这是 BOOTSTRAP 问题吗?
我是新手,收到此错误:
- 致命错误:在C:\wamp\NetBeansProjects\bomSlave\application\controllers\BomController.php第18行中找不到类“Form_UploadBom” >
我缺少什么??
我做错了什么?
正如您所期望的,BomController.php 的第 18 行是我调用表单实例的地方。
17. public function uploadAction() {
18. $form = new Form_UploadBom();
19. $this->view->form = $form;
20. }
我的表单位于 //application/forms/uploadbom.phtml
class Form_UploadBom extends Zend_Form {
public function __construct($option = null) {
parent::__construct($option);
$this->setName('bomupload');
$company = new Zend_Form_Element_Text('co');
$company->setLabel('Cust Company:')
->setRequired();
$contact = new Zend_Form_Element_Text('contact');
$contact->setLabel('Cust Contact')
->setRequired();
$file = new Zend_Form_Element_File('bom');
$file->setLabel('BOM File (in CSV):')
->setRequired();
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Uplaod BOM');
$this->addElements(array( $company, $contact, $file, $submit ));
$this->setMethod('post');
$this->setAction('');
}
}
这是我的 Bootstrap 文件中的自动加载程序
protected function _initAutoLoad(){
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH,
'resourceTypes' => array (
'model' => array(
'path' => 'models/',
'namespace' => 'Model_',
),
'form' => array(
'path' => 'forms/',
'namespace' => 'Form_',
)
)
)
);
return $autoloader;
}
再说一次,我缺少什么??
我做错了什么??
(请不要告诉我这只是某个地方的打字......
...那只会令人尴尬:)
~ Mo
[[编辑]]
好吧,将文件扩展名从 phtml 更改为 php 后,该错误消失了……但是……我现在遇到了有关视图助手的错误。
- 警告: Zend_View_Helper_Form::form() 缺少参数 1 ....
还有这个通知:
- 注意:* 未定义变量:名称位于 C:\wamp\bin\php\ZendFramework\1.11.11\library\Zend\View\Helper\Form.php 第 46
行进入游戏?
[[/编辑]]
I am a newbie, and getting this error:
- Fatal error: Class 'Form_UploadBom' not found in C:\wamp\NetBeansProjects\bomSlave\application\controllers\BomController.php on line 18
What am I missing ??
What am I doing wrong??
As you'd expect, line 18 of BomController.php is where I call for an instance of my form.
17. public function uploadAction() {
18. $form = new Form_UploadBom();
19. $this->view->form = $form;
20. }
My form is at //application/forms/uploadbom.phtml
class Form_UploadBom extends Zend_Form {
public function __construct($option = null) {
parent::__construct($option);
$this->setName('bomupload');
$company = new Zend_Form_Element_Text('co');
$company->setLabel('Cust Company:')
->setRequired();
$contact = new Zend_Form_Element_Text('contact');
$contact->setLabel('Cust Contact')
->setRequired();
$file = new Zend_Form_Element_File('bom');
$file->setLabel('BOM File (in CSV):')
->setRequired();
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Uplaod BOM');
$this->addElements(array( $company, $contact, $file, $submit ));
$this->setMethod('post');
$this->setAction('');
}
}
And here's the Auto Loader from my Bootstrap file
protected function _initAutoLoad(){
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH,
'resourceTypes' => array (
'model' => array(
'path' => 'models/',
'namespace' => 'Model_',
),
'form' => array(
'path' => 'forms/',
'namespace' => 'Form_',
)
)
)
);
return $autoloader;
}
Again, what am I missing ??
What am I doing wrong??
(and please don't tell me it's just a type-o somewhere ...
...that would just be embarrassing :)
~ Mo
[[EDIT]]
Well, after changing the file extension from phtml to php, that error is gone ... but ... I now have an error about view helpers.
- Warning: Missing argument 1 for Zend_View_Helper_Form::form() ....
And this notice:
- Notice:* Undefined variable: name in C:\wamp\bin\php\ZendFramework\1.11.11\library\Zend\View\Helper\Form.php on line 46
How does all that come into play ??
[[/EDIT]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到一些可能影响此问题的问题。
Zend_Form_Element_File 要求表单编码为:
$form->setAttrib('enctype', 'multipart/form-data');
Zend_Form_Element_File 需要一个目标集
$element->setDestination('/var/www/upload');
->setRequired()
默认情况下为 False,我很确定您需要将其标记为 true 才能使某个元素成为必需元素。$element->setRquired('TRUE');
扩展 Zend_Form 的表单的常见用法是在
init()
方法中构建表单,但它不是在 __construct() 中执行此操作在技术上是错误的。只是 Zend_Form 为此专门设置了init()
。第 3 和 4 不应该与您的 viewhelper 问题有任何关系,第 1 和 2 可能会。
也是一个观察...
如果您使用的是当前版本的 ZF (1.11),则引导程序中的
_initAutoload()
基本上是不必要的,因为表单和模型具有默认路由,并且您实际上不需要更改它们。要使用默认路由,您必须进行的唯一更改是确保您的 appNamespace 是类名的第一个单词。在正常的默认用法中,这将是“Application”...因此
Form_UploadBom()
将变为Application_Form_UploadBom()
。我意识到您可能已经完全知情并完成了此操作是故意的,而不仅仅是遵循一些过时的书籍或教程。如果是这样...代码:)
I've noticed a few issues that may affect this problem.
Zend_Form_Element_File requires that the form encoding be:
$form->setAttrib('enctype', 'multipart/form-data');
Zend_Form_Element_File needs a destination set
$element->setDestination('/var/www/upload');
->setRequired()
is False by default, I'm pretty sure you need to actually flag it as true to make an element required.$element->setRquired('TRUE');
Common usage of forms extending Zend_Form is to build the form in the
init()
method, it is not technically wrong to do it in__construct()
. It's just that Zend_Form specifically setsinit()
aside for this purpose.Number 3 and 4 should not have anything to do with your viewhelper issue, 1 and 2 likely will.
Also an observation...
If you are using the current version of ZF (1.11) your
_initAutoload()
in your bootstrap is largely unnecessary as forms and models have default routes and you're really not changing them.The only change you would have to make to use the default routes would be to make sure your appNamespace is the first word of the classname. In normal default usage that would be 'Application'... so
Form_UploadBom()
would becomeApplication_Form_UploadBom()
.I realize you may have done this fully informed and on purpose and are not just following some out of date book or tutorial. If so... code on :)
Zend_Application_Module_Autoloader
将_
替换为/
,以在路径application/forms/UploadBom 处查找表单
。Form_UploadBom
.php将表单的文件名更改为
文件扩展名
.phtml
仅用于查看相关内容。The
Zend_Application_Module_Autoloader
replaces_
with/
to find the formForm_UploadBom
at the pathapplication/forms/UploadBom.php
.Change the file name of your form to
The file extension
.phtml
is only used for view related stuff.