2010-01-13 41 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