2010-01-13 62 views
1

我试图在Zend_Form创建一个自定义表单字段来存储HTML片段由SWFUpload的需要(为一个Flash文件上传的目的),自定义表单元素。建立在Zend_Form中

我试过以下几个不同的教程,但我发现很困惑,到目前为止,这是我所:

/application/forms/elements/SwfUpload.php 
          SwfUploadHelper.php 

这些文件在引导被自动加载(当然,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 = '<div id="swfupload-control"> 
        <p>Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)</p> 
        <input type="button" id="button" /> 
        <p id="queuestatus" ></p> 
        <ol id="log"></ol> 
       </div>'; 
     return $html; 
    } 
} 

当我实例化这个类是这样的:

class Form_ApplicationForm extends Zend_Form 
{ 
    public function init() 
    { 
     $custom = new Custom_Form_Element_SwfUpload('swfupload'); 
     // etc etc 

我得到这个错误:

Message: Plugin by name 'SwfUpload' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:/home/mysite/application/views/helpers/

难道它希望帮助我的是在“home/mysite/application/views/helpers/”的情况?我试图创建在那里与文件名“SwfUpload.php”相同的助手,但仍然是错误。不知道这是纯粹的文件名/路径问题还是别的。

谢谢。

+0

这里是像你这样一个问题: http://stackoverflow.com/questions/2056737/add-html-placeholder-into-zendform/2056841 – 2010-01-13 15:26:21

+0

其实这就是我的问题太多,不打算垃圾邮件,但其对计算器困难时的问题样的变化圆通像这样的了。这更多的是理论的最新情况,这更多的是解决特定问题的案例。 – robjmills 2010-01-13 15:29:25

回答

9

这是我结束了,希望它可以帮助别人:

/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 = '<div id="swfupload-control"> 
        <p>Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)</p> 
        <input type="button" id="button" /> 
        <p id="queuestatus" ></p> 
        <ol id="log"></ol> 
       </div>'; 
     return $html; 
    } 
} 
4

API Docs for Zend_Form_Element

void __construct (string|array|Zend_Config $spec, [ $options = null]) 

    * string|array|Zend_Config $spec 
    * $options 

$spec may be: 

    * string: name of element 
    * array: options with which to configure element 
    * Zend_Config: Zend_Config with options for configuring element 

    * throws: Zend_Form_Exception if no element name after initialization 
    * access: public 

看看它抛出?尝试

$custom = new Custom_Form_Element_SwfUpload('upload'); 
+0

只注意到自己,D'哦。 – robjmills 2010-01-13 15:34:22