Answer the question
In order to leave comments, you need to log in
How to properly connect external modules in Yii2?
I'm trying to include Yii2-images. I did everything as described in the instructions :
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model, 'image');
if($model->image)
{
$path = Yii::getAlias('@webroot/upload/files').$model->image->baseName.'.'.$model->image->extension;
$model->image->saveAs($path);
$model->attachImage($path);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
namespace app\modules\admin\controllers;
use Yii;
use app\models\Product;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
Answer the question
In order to leave comments, you need to log in
is highlighted because it is a behavior method, not a class method. You need to write mixin
/**
* @mixin rico\yii2images\behaviors\ImageBehave
*/
then the methods of this behavior will be highlighted as class methods
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question