我正在尝试创建一个自定义表单字段Zend_Form
来存储SWFUpload所需的HTML片段(用于flash文件上传器的目的).
我已经尝试过几个不同的教程,但我感到非常困惑,到目前为止,这就是我所拥有的:
/application/forms/elements/SwfUpload.php SwfUploadHelper.php
这些文件在Bootstrap中自动加载(好吧,SwfUpload.php肯定是).
SwfUpload.php:
class Custom_Form_Element_SwfUpload extends Zend_Form_Element { public $helper = 'swfUpload'; }
SwfUploadHelper.php:
class Custom_Form_Helper_SwfUpload extends Zend_View_Helper_FormElement { public function swfUpload() { $html = ''; return $html; } }Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)
当我像这样实例化这个类:
class Form_ApplicationForm extends Zend_Form { public function init() { $custom = new Custom_Form_Element_SwfUpload('swfupload'); // etc etc
我收到此错误:
消息:在注册表中找不到名称为"SwfUpload"的插件; 使用的路径:Zend_View_Helper_:Zend/View/Helper /:/ home/mysite/application/views/helpers /
它是否预期我的助手会在" home/mysite/application/views/helpers/
"?我尝试使用文件名"SwfUpload.php"在那里创建相同的帮助程序,但错误仍然存在.不确定我这纯粹是文件名/路径问题还是其他问题.
谢谢.
这就是我最终的结果,希望它可以帮助别人:
在 /application/forms/elements/SwfUpload.php
class Custom_Form_Element_SwfUpload extends Zend_Form_Element { public $helper = 'swfUpload'; # maps to method name in SwfUpload helper public function init() { $view = $this->getView(); $view->addHelperPath(APPLICATION_PATH.'/views/helpers/', 'Custom_Form_Helper'); } }
在 /application/views/helpers/SwfUpload.php
class Custom_Form_Helper_SwfUpload extends Zend_View_Helper_FormElement { public function init(){} public function swfUpload() { $html = ''; return $html; } }Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)