0
如何通過擴展zend表單元素來製作自定義圖像文件?在HTML輸出結果是象下面這樣:如何使用zend框架製作自定義圖像文件格式
<div class="image-file-wrapper">
<img src="yourimagepath" />
<br />
<input id="image-file" name="image-file" type="file" />
</div>
UPDATE:
我的自定義表單元素
class Engine_Form_Element_ImageFile extends Zend_Form_Element_File {
public $helper = 'FormImageFile';
protected $_image;
public function setImage($src) {
$this->_image = $src;
return $this;
}
public function loadDefaultDecorators() {
if($this->loadDefaultDecoratorsIsDisabled()) {
return;
}
$decorators = $this->getDecorators();
if(empty($decorators)) {
$this->addDecorator('ViewHelper');
Engine_Form::addDefaultDecorators($this);
}
}
}
我的自定義視圖助手:
class Engine_View_Helper_FormImageFile extends Zend_View_Helper_FormElement {
public function formImageFile($name, $value = null, $attribs = null, $options = null) {
return '<div class="image-file-wrapper"><img src="test.png" /><input type="file" /></div>';
}
}
當我嘗試添加它,
$this->addElement('ImageFile', 'imageFile', array('label' => 'Test Image'));
錯誤發生:
Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 C:\xampp\htdocs\NEOBBS_v6\library\Zend\Form\Decorator\FormElements.php(101): Zend_Form_Element_File->render() #1 C:\xampp\htdocs\NEOBBS_v6\library\Zend\Form.php(2904): Zend_Form_Decorator_FormElements->render('') #2 C:\xampp\htdocs\NEOBBS_v6\library\Zend\Form.php(2920): Zend_Form->render() #3 C:\xampp\htdocs\NEOBBS_v6\application\themes\admin\settings.phtml(8): Zend_Form->__toString() #4 C:\xampp\htdocs\NEOBBS_v6\library\Zend\View.php(108): include('C:\xampp\htdocs...') #5 C:\xampp\htdocs\NEOBBS_v6\library\Zend\View\Abstract.php(880): Zend_View->_run('C:\xampp\htdocs...') #6 C:\xampp\htdocs\NEOBBS_v6\library\Zend\Controller\Action\Helper\ViewRenderer.php(897): Zend_View_Abstract->render('settings.phtml') #7 C:\xampp\htdocs\NEOBBS_v6\library\Zend\Controller\Action.php(243): Zend_Controller_Action_Helper_ViewRenderer->renderScript('settings.phtml', NULL) #8 C:\xampp\htdocs\NEOBBS_v6\application\modules\admin\contr in C:\xampp\htdocs\NEOBBS_v6\library\Zend\Form.php on line 2925
如何解決呢?
由於提前,
布賴恩
是的,但我總是得到錯誤:警告:異常由形式:插件名稱'FormImageFile'在註冊表中找不到;使用路徑: – brian 2011-06-12 15:18:25