Yii2 UploadedFile::getInstance()返回null
发送我的表单时,Yii2 UploadedFile::getInstance()返回null,yii2,yii2-advanced-app,Yii2,Yii2 Advanced App,发送我的表单时,UploadedFile::getInstance($model,'images')返回null。我还尝试了上传文件::getInstanceByName('images')。在$\u POST数组中,images键为空,例如'images'=>[''']。该文件存在于$\u FILES数组中 我的代码非常简单。我的看法是: <?php $form = ActiveForm::begin([ 'options' => [ 'class' =&g
UploadedFile::getInstance($model,'images')
返回null
。我还尝试了上传文件::getInstanceByName('images')
。在$\u POST
数组中,images
键为空,例如'images'=>[''']
。该文件存在于$\u FILES
数组中
我的代码非常简单。我的看法是:
<?php $form = ActiveForm::begin([
'options' => [
'class' => 'validation-wizard wizard-circle floating-labels',
'enctype'=>'multipart/form-data'
],
]); ?>
<?= $form->field($model, 'images[]')->fileInput([
'id' => 'image_0',
'class' => 'dropify',
'data-default-file' => ''
]) ?>
<?php ActiveForm::end() ?>
如果要访问文件数组,则需要使用而不是
UploadedFile::getInstance()
处理多个文件的好例子可以在第节的指南中找到。为什么使用
图像[]
作为字段名而不是图像
?因为我需要多个图像。但也尝试了在单个图像中使用不带括号的whitimages
。结果是一样的。然后你应该使用getInstances()
而不是getInstance()
。效果很好。多谢各位。你可以把你的答案贴在下面,让我批准。
public $images;
public function rules()
{
return [
['images', 'each', 'rule' => ['file']],
];
}
$files = UploadedFile::getInstances($model, 'images');