0

zendフォーム要素を拡張してカスタム画像ファイルを作成するにはどうすればよいですか?htmlでの出力は次のようになります。

<div class="image-file-wrapper">
     <img src="yourimagepath" />
     <br />
     <input id="image-file" name="image-file" type="file" />
</div>

アップデート:

私のカスタムフォーム要素

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

どうすれば修正できますか?

前もって感謝します、

ブライアン

4

1 に答える 1

0

Zend_Form_Decorator_ViewScript を使用します。詳細: http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript

于 2011-06-12T14:58:35.240 に答える