Answer the question
In order to leave comments, you need to log in
Yii2 REST Why public $modelClass = 'app\models\Photo'; is null?
I'm trying to load images, but for some reason the model returns null
My model
class Photo extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'photo';
}
public $imageFile;
public function rules() {
return [
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
];
}
public function upload()
{
if ($this->validate()) {
$this->imageFile->saveAs('img/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
}
class PhotoController extends ActiveController {
public $modelClass = 'app\models\Photo';
public $enableCsrfValidation = false;
public function actions() {
$actions = parent::actions();
unset($actions['create']);
return $actions;
}
public function actionCreate() {
$modelClass->imageFile = UploadedFile::getInstance($modelClass, 'imageFile');
$modelClass->upload()
return $modelClass;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question