forms - CUploadedFile::getInstance Always Returns Null on Uploaded File -
i have built form in yii , need process uploaded file. followed this guide, i've stumbled upon issue. cuploadedfile::getinstance
returns null.
here's use. model:
class additionalfieldfile extends cformmodel { public $uploadedfile; /** * @return array validation rules model attributes. */ public function rules() { return array( //note wont need safe rule here array('uploadedfile', 'file', 'allowempty' => true, 'types' => 'zip,doc,xls,ppt,jpg,gif,png,txt,docx,pptx,xlsx,pdf,csv,bmp'), ); } }
and handling uploaded file in controller on form submit:
$model = new additionalfieldfile(); $model->uploadedfile = cuploadedfile::getinstance($model, 'field_'.$type_field.'['.$id_common.']');
and after $model->uploadedfile
null reason.
note $type_field
, $id_common
come dynamically.
also, form has 'enctype'=>'multipart/form-data'
not cause.
ok, self-answer follows.
it turns out had use active file field in view, using instance of class extends cformmodel
model.
solution:
chtml::activefilefield(new additionalfieldfile(), 'field_'.$type_field.'['.$id_common.']');
Comments
Post a Comment