пытаюсь организовать загрузку вот модель
class ImageUpload extends Model
{
public $imageFiles;
public function rules()
{
return [
[['imageFiles'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
];
}
public function upload(){
$uploadPath=\Yii::getAlias('@app').'/web/image/post/'.date('Y').'/'.date('m');
BaseFileHelper::createDirectory($uploadPath);
if ($this->validate()) {
foreach ($this->imageFiles as $file) {
$imageFile=$uploadPath . '/' . $file->baseName.'.'.$file->extension;
$file->saveAs($imageFile);
}
return true;
}
return var_dump($this->getErrors());
}
}
вот контролер
class PostController extends Controller
{
public function actionCreate()
{
$model = new Post();
$imageUpload= new ImageUpload();
if ($model->load(Yii::$app->request->post())) {
$imageUpload->imageFiles = UploadedFile::getInstances($imageUpload, 'imageFiles');
$image=$imageUpload->upload();
$saves=$model->saves($image,$model);
if($saves){
return $this->render('create',[
'model' => $model,
'imageUpload'=>$imageUpload
]);
}
return var_dump($image);
} else {
return $this->render('create', [
'model' => $model,
'imageUpload'=>$imageUpload
]);
}
}
вот вид
<div class="post-form">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'content')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
]) ?>
<?= $form->field($imageUpload, 'imageFiles[]')->fileInput(['multiple' => true]) ?>
<?= $form->field($model, 'preview')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
получаю ошибку please upload file в дебаге
ImageUpload пустой а $_FILE полный почему не подскажите ? И что делать?