вот контролер
public function actionCreate(){
$module=$this->module;
$model= new MenuGet();
$uploadModel=new UploadImage();
if (Yii::$app->request->isAjax) {
$request=Yii::$app->request;
if($request->isPost){
$fileName = 'file';
if (isset($_FILES[$fileName])) {
$file = \yii\web\UploadedFile::getInstanceByName($fileName);
$uplImg=$uploadModel->upload($file ,$module);
if ($uplImg) {
return $this->render('create', [
'model' => $model,
'module' => $module,
'uploadModel' => $uploadModel
]);
}
}
}
вот UploadImage
class UploadImage extends Model
{
public $file;
public function rules()
{
return [
[['file'], 'file','skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
];
}
public function upload($fileName,$module){
$basePath=date('Y').'/'.date('m');
$uploadPath =$module->imageDownloadPath.''.$basePath;
if (file_exists($uploadPath)) {
} else {
mkdir($uploadPath, 0777, true);
}
$file = \yii\web\UploadedFile::getInstanceByName($fileName);
$filenames=$this->traranslitImg($file->name);
if ($this->validate()) {
if(file_exists($uploadPath)) {
} else {
mkdir($uploadPath, 0777, true);
}
if ($this->file->saveAs($uploadPath . '/' . $filenames)){
$this->imagerisize($uploadPath, $filenames,$module);
return true;
};
} else {
return var_dump($this->getErrors());
}
}
картинка грузится через dropzone но приходит ответ
Exception 'Error' with message 'Call to a member function saveAs() on null'
in /var/www/magaz.lc/vendor/sirgalas/yii2-wordperss-menu/models/UploadImage.php:41