我正在尝试上传照片,我有一个Zend_form:
class Application_Form_EditUser extends Zend_Form {
public function init() {
//$date = date("d/m/y : H:i:s", time());
//$path = '/ImagesUsers/' .Zend_Auth::getInstance()->getIdentity()->id.'/avatar'.$date
$form = new Zend_Form();
$form->setMethod('post')
->setName('upload')
->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
$form->setAttrib('enctype', 'multipart/form-data');
$this->setAction('/User/edit');
$this->addElement('text', 'name', array(
'label' => 'Name: ',
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('text', 'surname', array(
'label' => 'Surname: ',
'required' => false,
'filters' => array('StringTrim'),
));
$this->addElement('text', 'nickname', array(
'label' => 'Nickname: ',
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('radio', 'sex', array(
'label' => 'Gender: ',
'required' => true,
'multiOptions' => array(
'F' => 'Female',
'M' => 'Male',
),
'value' => 'F',
));
$this->addElement('text', 'skype', array(
'label' => 'Skype: ',
'required' => false,
'filters' => array('StringTrim'),
));
$this->addElement('textarea', 'description', array(
'label' => 'Describe yourself: ',
'required' => false,
'style' => 'width: 60%; height: 70px;',
));
$image = new Zend_Form_Element_File('image');
$image->setLabel('Upload an avatar:')
->setMaxFileSize(10240000)
->setDestination('./usersImages/')
->setDescription('Click Browse and choose an image');
$image->addValidator('Count', false, 1);
$image->addValidator('Size', false, 10240000);
$image->addValidator('Extension', false, 'jpg,jpeg,png,gif');
$form->addElement($image, 'image');
$this->addElement('submit', 'update', array(
'label' => 'Save changes',
'ignore' => true,
'required' => true,
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
array('Description', array('placement' => 'prepend')),
'Form'
));
}
}
喜欢你可以看到有Zend_Form_Element_File但我在我的页面上看不到它?为什么呢?
此源生成此pagesource:
<form enctype="application/x-www-form-urlencoded" action="/User/edit/" method="post"><dl class="zend_form">
<dt id="name-label"><label for="name" class="required">Name:</label></dt>
<dd id="name-element">
<input type="text" name="name" id="name" value="Test1Name" /></dd>
<dt id="surname-label"><label for="surname" class="optional">Surname:</label></dt>
<dd id="surname-element">
<input type="text" name="surname" id="surname" value="Test1Surname" /></dd>
<dt id="nickname-label"><label for="nickname" class="required">Nickname:</label></dt>
<dd id="nickname-element">
<input type="text" name="nickname" id="nickname" value="Test1NickName" /></dd>
<dt id="sex-label"><label class="required">Gender:</label></dt>
<dd id="sex-element">
<label for="sex-F"><input type="radio" name="sex" id="sex-F" value="F" checked="checked" />Female</label><br /><label for="sex-M"><input type="radio" name="sex" id="sex-M" value="M" />Male</label></dd>
<dt id="skype-label"><label for="skype" class="optional">Skype:</label></dt>
<dd id="skype-element">
<input type="text" name="skype" id="skype" value="" /></dd>
<dt id="description-label"><label for="description" class="optional">Describe yourself:</label></dt>
<dd id="description-element">
<textarea name="description" id="description" style="width: 60%; height: 70px;" rows="24" cols="80"></textarea></dd>
<dt id="update-label"> </dt><dd id="update-element">
<input type="submit" name="update" id="update" value="Save changes" /></dd></dl></form>
但我的上传元素在哪里?我正在寻找一个错字或错误1小时我检查它应该在zend页面上,但我仍然无法理解为什么我看不到它?
答案 0 :(得分:1)
不应该$ form-&gt; addElement($ image,'image')是$ this-&gt; addElement($ image,'image')?