/** * Creates a new Asset model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Asset(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->Id]); } else { return $this->render('create', ['model' => $model]); } }
protected function importimagefromstr($media, $path, $flag) { $mediaIds = []; yii::info($media, __METHOD__); $hash = md5($media); if (($armodel = Asset::findOne(['mediahash' => $hash])) !== null) { return [$armodel->Id]; } $media_doc = ['filename' => $media, 'path' => '@media/' . $path . '/' . $media, 'uri' => $path . '/' . $media, 'description' => '', 'mimetype' => '', 'source' => '', 'embedcode' => '', 'mediahash' => $hash, 'metainfo' => '', 'createdBy' => 40, 'updatedBy' => 40, 'status' => 1]; $assetmodel = new Asset(); $assetmodel->load($media_doc, ''); $assetmodel->save(false); $mediaIds[] = $assetmodel->Id; try { $tag = Asset::loadTagmodel($flag, true); Asset::saveAssetTag($assetmodel, $tag); } catch (\yii\base\ErrorException $error) { Yii::info(print_r($error, true), __METHOD__); } return $mediaIds; }