[英]Yii:user - file Profile Field
I've added a file type Profile Field in Yii:user. 我在Yii:user中添加了文件类型Profile Profile。 The file selection was added to the profile edit form, but when I select an image I get an error "Image cannot be blank". 文件选择已添加到配置文件编辑表单,但是当我选择图像时,出现错误“图像不能为空白”。
I've set the ajax validation to false and now I get this error after submit. 我已经将ajax验证设置为false,现在在提交后收到此错误。
What should I do? 我该怎么办?
您需要编辑您的个人资料字段,并将其他验证器值设置为如下所示:
{"file":{"allowEmpty":"true","maxFiles":"1","types":"jpg, jpeg, gif, png"}}
Two important things you need to do: add a new validation rule to the Profile Field model that looks something like this: 您需要做的两件重要事情:将一个新的验证规则添加到Profile Field模型中,如下所示:
array('image', 'file', 'types'=>'jpg, gif, png'),
And change the form tag to include 'enctype'=>'multipart/form-data' (I normally add that using the htmlOptions array in CActiveForm / CForm). 并将表单标签更改为包括“ enctype” =>“ multipart / form-data”(我通常使用CActiveForm / CForm中的htmlOptions数组添加该标签)。
Here is a wiki page talking about how to upload files using a model, in case you haven't seen it yet: http://www.yiiframework.com/wiki/2/ 这是一个Wiki页面,讨论如何使用模型上传文件,以防万一您尚未看到它: http : //www.yiiframework.com/wiki/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.