FileField的默认属性怎么设置?

我在做一个图片管理的小项目,因为要对图片进行修改,我的想法是,如果用户不重新上传文件,则不修改图片在数据库中的路径,但FileField没有默认值,大家说一下都是怎么解决的?


<div class="row">

	<?php echo $form->labelEx($model,'title'); ?>

	<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>200)); ?>

	<?php echo $form->error($model,'title'); ?>

</div>


<div class="row">

	<?php echo $form->labelEx($model,'content'); ?>

	<?php echo $form->textArea($model,'content',array('rows'=>6, 'cols'=>50)); ?>

	<?php echo $form->error($model,'content'); ?>

</div>


<div class="row">

	<?php echo $form->labelEx($model,'image'); ?>

	<?php echo $form->FileField($model,'image'); ?> //这里怎么才能实现<input type="file" value="{原来的值}" />

	<?php echo $form->error($model,'image'); ?>

</div>

基于安全性考虑, 文件域的值是不允许赋值,默认就是空~

<div class="row">

&lt;label for=&quot;Picture_image&quot;&gt;图片&lt;/label&gt;		


&lt;input id=&quot;ytPicture_image&quot; type=&quot;hidden&quot; value=&quot;&quot; name=&quot;Picture[image]&quot; /&gt;


&lt;input name=&quot;Picture[image]&quot; id=&quot;Picture_image&quot; type=&quot;file&quot; /&gt;

</div>

这是页面的源文件,用FileField为什么前面多了个<input id="ytPicture_image" type="hidden" value="" name="Picture[image]" />,API里也没有说明啊?

这个隐藏域应该是可以存放默认值的,但是用CActiveForm怎么去把这个参数加进去呢?

<div class="row">

&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'image'); ?&gt;


&lt;?php echo &#036;form-&gt;FileField(&#036;model,'image'); ?&gt; //这里如果能把&#036;model-&gt;image写进&lt;input id=&quot;ytPicture_image&quot; type=&quot;hidden&quot; value=&quot;&quot; name=&quot;Picture[image]&quot; /&gt;的默认值就行了





&lt;?php echo &#036;form-&gt;error(&#036;model,'image'); ?&gt;

</div>

我感觉这个功能很有必要,如果不用CActiveForm,是很好实现的,在线等答案!

你可以在 afterFind 之后将原来的图片地址取出来,在保存的时候,如果没有上传新的文件的话,就直接赋予原来的地址就可以了。

嗯,这好像是个好方法,我试一下!