CostaRico / yii2-images

Yii2-images - behavior-based module for resizing, storing, caching and attaching images.
160 stars 98 forks source link

Call to a member function setMain() on null. #60

Open Batisska opened 7 years ago

Batisska commented 7 years ago

Доброй ночи.

Пытаюсь сохранить картинку.

if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->img = UploadedFile::getInstance($model, 'img'); if ($model->img){ $path = Yii::getAlias('@webroot/uploads/boats/').$model->img->baseName.'.'.$model->img->extension; $model->img->saveAs($path); $model->attachImage($path,true); } return $this->redirect(['index','id'=> $model->id ]); }

Выдает вот такую ошибку.

in D:\OpenServer\domains\kater\vendor\costa-rico\yii2-images\behaviors\ImageBehave.php at line 139 130131132133134135136137138139140141142143144145146147148
$images = $this->owner->getImages(); foreach ($images as $allImg) {

        if ($allImg->id == $img->id) {
            continue;
        } else {
            $counter++;
        }

        $allImg->setMain(false);
        $allImg->urlAlias = $this->getAliasString() . '-' . $counter;
        $allImg->save();
    }

    $this->owner->clearImagesCache();
}

/**
 * Clear all images cache (and resized copies)> 

При этом картинку сохраняет.