public function insertImage($event) { $images = Yii::$app->request->post('upload_files'); if (is_null($images) || !is_array($images)) { return; } foreach ($images as $image) { $model = new Images(); $model->attributes = ['model_name' => $this->getOwnerClass(), 'model_id' => $this->owner->id, 'type' => Images::TYPE_NORMAL, 'file' => $image, 'category' => 'products']; $model->save(); } }
protected function findImageModel($id) { if (($model = Images::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }