用Yii的ActiveForm上传文件 [英] File upload with Yii's ActiveForm
问题描述
$ $ p $ $ this $> beginWidget('CActiveForm', array $(
'id'=>'activity_form',
'enableAjaxValidation'=> true,
'stateful'=> true,
'enctype'=> 'multipart / form-data'
));
以上代码在Yii中产生以下错误消息:
属性CActiveForm.enctype未定义
我也试过:
$ form = $ this-> beginWidget('CActiveForm',array(
'id'=>'activity_form',$ b $'enableAjaxValidation'=> true ,
'stateful'=> true,
array('enctype'=>'multipart / form-data')));
以及:
$ form = $ this-> beginWidget('CActiveForm',array(
'id'=>'activity_form',
'enableAjaxValidation'=> true,
'stateful'=> true),
array('enctype'=>'multipart / form-data')));
但这两者都不起作用。
任何想法可能是错误的?我可以使用beginWidget创建具有文件上传功能的多部分表单吗?我应该遵循什么格式?我似乎无法在文档或论坛中找到任何答案。
谢谢!
没关系。我找到了解决办法。诀窍是像这样使用htmlOptions:
$ $ $ this-> beginWidget('CActiveForm',array(
'id'=>'activity_form',
'enableAjaxValidation'=> true,
'stateful'=> true,
'htmlOptions'=> array('enctype'= >'multipart / form-data')
));
I am trying to use Yii's ActiveForm to create a basic registration page with an image upload field. However, I am running into problems. I am using the following code to create the form tags:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
'enctype'=>'multipart/form-data'
));
The above code produces the following error message in Yii:
Property "CActiveForm.enctype" is not defined
I've also tried:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
array('enctype'=>'multipart/form-data')));
as well as:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true),
array('enctype'=>'multipart/form-data')));
But neither of these work.
Any ideas as to what could be wrong? Can I use beginWidget to create a multipart form with file upload capabilities? What's the format I should follow for this? I can't seem to find any answers in the documentation or the forums.
Thanks!
Never mind. I found the solution to this. The trick is to use htmlOptions like so:
$this->beginWidget('CActiveForm', array(
'id'=>'activity_form',
'enableAjaxValidation'=>true,
'stateful'=>true,
'htmlOptions'=>array('enctype' => 'multipart/form-data')
));
这篇关于用Yii的ActiveForm上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!