/** * Upload file to server. * * @param bool $printResponse * * @return array * @throws \yii\web\NotFoundHttpException */ public function post($printResponse = true) { if (Yii::$app->request->get('delete') && ($id = Yii::$app->request->get('id'))) { return $this->delete($id, $printResponse); } $response = []; $this->_media = new Media(); $this->_media->file = UploadedFile::getInstance($this->_media, 'file'); if ($this->_media->file !== null && $this->_media->validate(['file'])) { if ($post_id = Yii::$app->request->get('post_id')) { $post = $this->findPost($post_id); $this->_media->media_post_id = $post->id; } $this->_media->media_title = $this->_media->file->baseName; $this->_media->media_mime_type = $this->_media->file->type; $this->handleFileUpload($this->_media->file); if ($this->_media->save()) { if ($this->_media->setMeta('metadata', $this->_meta)) { $response = $this->generateResponse($this->_media); } } } else { $response[] = ['media_error' => $this->_media->getErrors('file'), 'media_filename' => isset($this->_media->file->name) ? $this->_media->file->name : null, 'media_file_size' => isset($this->_media->file->size) ? $this->_media->file->size : null]; } $this->setResponse([$this->getOption('param_name') => [$response]]); return $this->getResponse($printResponse); }
public function actionAjax() { $media = new Media(); $uploaddir = 'media_file/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); if (!empty($_FILES)) { if (copy($_FILES['file']['tmp_name'], $uploadfile)) { $media->link = $uploadfile; $media->save(); } } $mediaAll = Media::find()->all(); foreach ($mediaAll as $m) { echo "\n <div class='mediaBox'>\n " . Html::img(\yii\helpers\Url::base() . "/" . $m->link, ['width' => '150px', 'class' => 'imgPrev']) . "\n <input type='hidden' value='" . \yii\helpers\Url::base(true) . "/" . $m->link . "'>\n </div>"; } }
/** * Finds the Media model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param string $media_slug * * @return Media the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelBySlug($media_slug) { if (($model = Media::findOne(['media_slug' => $media_slug])) !== null) { return $model; } throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); }
public function getPreview($options = array()) { if (empty($this->previewEntity)) { $model = new Media(); $media = $model->findByParams(array(Media::ENCODE_ENTITY => Entity::TYPE_WIDGET, Media::ENCODE_ID => $this->id, Media::ENCODE_ITEMNO => $this->previewRefId)); if ($media == null) { return null; } $imgTag = Html::img(\Yii::getAlias('@web') . '/media/' . $media->getPublishUri($options), array()); return $imgTag; } else { $model = Entity::getInstance($this->previewEntity, $this->previewRefId); if ($model != null) { return $model->getPreview($options); } } }
/** * Finds the Message model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Message the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Media::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing Menu model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $media = Media::find()->orderBy('id DESC')->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'media' => $media]); } }
/** * @param AcceptanceTester $I */ public function testUpdate(AcceptanceTester $I) { $I->wantTo('ensure that update page works'); $updatePage = UpdatePage::openBy($I); $I->see('Update Media', 'h1'); $I->amGoingTo('submit update media form'); $updatePage->submit(['title' => 'test123', 'excerpt' => 'TEST QWERT']); $I->expect('media updated'); Media::findOne(1)->updateAttributes(['title' => 'Test Media', 'excerpt' => 'Test Media Caption']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Media::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'value' => $this->value, 'created' => $this->created, 'updated' => $this->updated]); return $dataProvider; }
/** * Updates an existing Pages model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $media = Media::find()->orderBy('id DESC')->all(); $block = Block::find()->where(['type' => ''])->all(); $arr[0] = 'Нет'; foreach ($block as $b) { $arr[$b->id] = $b->name; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'media' => $media, 'block' => $arr]); } }
/** * @param FunctionalTester $I */ public function testProtected(FunctionalTester $I) { Media::findOne(1)->updateAttributes(['password' => 'mediapassword']); $I->wantTo('ensure that protected media works'); $mediaView = MediaViewPage::openBy($I); $I->see('Test Media', 'h1'); $I->amGoingTo('submit password form with incorrect password'); $mediaView->submitPassword('wrong_password'); $I->expectTo('not see the media'); $I->dontSeeElement('.entry-meta'); $I->amGoingTo('submit password form with correct password'); $mediaView->submitPassword('mediapassword'); $I->expectTo('see the post'); $I->seeElement('.entry-meta'); $I->seeLink('Test Media'); Media::findOne(1)->updateAttributes(['password' => '']); }
/** * Creates data provider instance with search query applied * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = MediaModel::find(); $query->innerJoinWith(['mediaAuthor' => function ($query) { /* @var $query \yii\db\ActiveQuery */ return $query->from(['user' => User::tableName()]); }])->from(['media' => $this->tableName()]); $query->leftJoin(['post' => Post::tableName()], 'media.post_id = post.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['media.id' => $this->id, 'media.author' => $this->author, 'post_id' => $this->post_id, 'media.comment_count' => $this->comment_count]); $query->andFilterWhere(['like', 'media.title', $this->title])->andFilterWhere(['like', 'media.excerpt', $this->excerpt])->andFilterWhere(['like', 'media.content', $this->content])->andFilterWhere(['like', 'media.password', $this->password])->andFilterWhere(['like', 'media.slug', $this->slug])->andFilterWhere(['like', 'mime_type', $this->mime_type])->andFilterWhere(['like', 'media.comment_status', $this->comment_status])->andFilterWhere(['like', 'media.date', $this->date])->andFilterWhere(['like', 'media.modified', $this->modified])->andFilterWhere(['like', 'post.title', $this->post_title])->andFilterWhere(['like', 'user.username', $this->username]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MediaModel::find()->from(['media' => $this->tableName()]); $query->innerJoinWith(['mediaAuthor' => function ($query) { /* @var $query \yii\db\ActiveQuery */ return $query->from(['author' => User::tableName()]); }]); $query->leftJoin(['post' => Post::tableName()], 'media.media_post_id = post.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'media_author' => $this->media_author, 'media_post_id' => $this->media_post_id, 'media_comment_count' => $this->media_comment_count]); $query->andFilterWhere(['like', 'media_title', $this->media_title])->andFilterWhere(['like', 'media_excerpt', $this->media_excerpt])->andFilterWhere(['like', 'media_content', $this->media_content])->andFilterWhere(['like', 'media_password', $this->media_password])->andFilterWhere(['like', 'media_slug', $this->media_slug])->andFilterWhere(['like', 'media_mime_type', $this->media_mime_type])->andFilterWhere(['like', 'media_comment_status', $this->media_comment_status])->andFilterWhere(['like', 'media_date', $this->media_date])->andFilterWhere(['like', 'media_modified', $this->media_modified])->andFilterWhere(['like', 'post.post_title', $this->post_title])->andFilterWhere(['like', 'author.username', $this->username]); return $dataProvider; }
private static function _mediaDecoder($attributes) { $baseUrl = \Yii::$app->homeUrl; $id = $attributes['id']; $type = Entity::mapType($attributes['object']); $itemNo = $attributes['itemno']; $items = array(); $output = ''; /* $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('refId'=> $id, 'type'=> $type, 'itemNo'=>$itemNo)); */ $query = Media::find(); $query->andWhere(['refId' => $id, 'type' => $type, 'itemNo' => $itemNo]); $options = array(Media::ENCODE_WIDTH => 100); $lst = Media::getItems($query, $options); $items = array_shift($lst); $output .= "<media id=\"{$items['refId']}\" object=\"{$attributes['object']}\" itemno=\"{$items['itemNo']}\">"; $output .= '<img src="' . $baseUrl . 'media/' . $items['fullPath'] . '">'; $output .= '<p class="caption">' . $items['caption'] . '</p></media>'; return $output; }
/** * Updates an existing Category model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $parent = Categories::find()->all(); $media = Media::find()->orderBy('id DESC')->all(); $block = Block::find()->where(['type' => ''])->all(); $arr = CategoryTree::getTreeSelect(0); $arr1[0] = 'Нет'; foreach ($block as $v) { $arr1[$v->id] = $v->name; } /*$arr[0] = 'Нет'; foreach($parent as $v){ $arr[$v->id]=$v->name; }*/ if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'parent' => $arr, 'media' => $media, 'block' => $arr1]); } }
/** * Updates an existing Supplies model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $media = Media::find()->orderBy('id DESC')->all(); $type_mat = Material::find()->all(); $type_blind = array(0 => 'Выберите тип жалюзеу', 1 => 'горизонтальные', 2 => 'рулонные', 3 => 'вертикальные'); $arr_tmat[0] = 'Выберите тип материала'; foreach ($type_mat as $v) { $arr_tmat[$v->id] = $v->name; } $color = Color::find()->all(); $arr_color[0] = 'Выберите цвет'; foreach ($color as $v) { $arr_color[$v->id] = $v->value; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'media' => $media, 'type_mat' => $arr_tmat, 'type_blind' => $type_blind, 'color' => $arr_color]); } }
/** * @return \yii\db\ActiveQuery */ public function getMedia() { return $this->hasOne(Media::className(), ['id' => 'media_id']); }
?> <?php } ?> </div> <div class="col-sm-4"> <?php if (($widget = Media::find()->where(['type' => 2])->one()) != null) { ?> <?php echo Html::decode($widget->value); ?> <?php } ?> </div> <div class="col-sm-4"> <?php if (($widget = Media::find()->where(['type' => 1])->one()) != null) { ?> <?php echo Html::decode($widget->value); ?> <?php } ?> </div> </div> </div> </div> </div>
/** * Finds the Media model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $id * * @return Media the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findMedia($id) { if (($model = Media::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.')); }
/** * Updates an existing Blind model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $blind = Blind::find()->where(['id' => $id])->one(); $model = new BlindForm(); $model->name = $blind->name; $model->status = $blind->status; $model->description = $blind->description; $model->tab = $blind->tab; $cat = BlindCatid::find()->where(['id_blind' => $id])->all(); $blindMaterialHeader = BlindMaterials::find()->where(['id_blind' => $id])->all(); //Debag::prn($_POST); foreach ($cat as $c) { $arr_catid[$c->id_cat] = ['selected ' => 'selected']; } $media = Media::find()->orderBy('id DESC')->all(); $supples = BlindIdmaterials::find()->where(['id_blind' => $id])->all(); foreach ($supples as $supl) { $arr_supl[$supl->id_materials] = ['selected ' => 'selected']; } $materials = \backend\modules\supplies\models\Supplies::find()->all(); foreach ($materials as $v) { $arr_materials[$v->id] = $v->code; } $arr_cat = CategoryTree::getTreeSelect(0); unset($arr_cat[0]); $blImg = new BlindImg(); $imgages = $blImg->find()->where(['id_blind' => $id])->all(); $addMaterials = \common\classes\Supplies::getAddSupplies(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $blind->name = $model->name; $blind->status = $model->status; $blind->description = $model->description; $blind->tab = $model->tab; $blind->save(); $delBmt = new BlindMaterials(); $delBmt->deleteAll(['id_blind' => $blind->id]); if (isset($_POST['blindTitle'])) { foreach ($_POST['blindTitle'] as $bt) { $arrBt = explode('*', $bt); $bmt = new BlindMaterials(); $bmt->id_blind = $blind->id; $bmt->id_materials = $arrBt[0]; $bmt->title = $arrBt[1]; $bmt->save(); } } $cat = BlindCatid::deleteAll(['id_blind' => $blind->id]); foreach ($model->categories as $cat) { $blindCatId = new BlindCatid(); $blindCatId->id_blind = $blind->id; $blindCatId->id_cat = $cat; $blindCatId->save(); } $blindImg = new BlindImg(); $cat = $blindImg->deleteAll(['id_blind' => $blind->id]); if (!empty($_POST['blind_image'])) { foreach ($_POST['blind_image'] as $img) { $blindImg = new BlindImg(); $imgarr = explode('*', $img); $blindImg->id_blind = $blind->id; $blindImg->images = $imgarr[0]; $blindImg->main = $imgarr[1]; $blindImg->save(); } } $cat = BlindIdmaterials::deleteAll(['id_blind' => $blind->id]); if (!empty($model->materials)) { foreach ($model->materials as $mat) { $blindMat = new BlindIdmaterials(); $blindMat->id_blind = $blind->id; $blindMat->id_materials = $mat; $blindMat->save(); } } //Debag::prn($_POST['infoPage']); $zag = PageToBlind::find()->where(['id_blind' => $blind->id])->all(); foreach ($zag as $v) { PageBlinds::deleteAll(['id' => $v->id_pages]); } PageToBlind::deleteAll(['id_blind' => $blind->id]); if (isset($_POST['infoPage'])) { foreach ($_POST['infoPage'] as $v) { $input = explode('*', $v); $s = str_replace('_', ' ', $input[0]); $pb = PageBlinds::find()->where(['name' => $s])->one(); if (empty($pb->id)) { $pb = new PageBlinds(); $pb->name = $s; $pb->save(); } //$pb->name = $input[0]; //$pb->save(); unset($input[0]); $del = PageToBlind::deleteAll(['id_pages' => $pb->id]); $ptb = new PageToBlind(); $ptb->id_pages = $pb->id; $ptb->id_blind = $blind->id; $ptb->save(); $cat = PageItem::deleteAll(['id_page' => $pb->id]); foreach ($input as $in) { //Debag::prn($in); $pageItem = new PageItem(); $item = explode('_', $in); if ($item[1] == 'materials') { $pageItem->id_page = $pb->id; $pageItem->id_item = $item[0]; $pageItem->item_type = 'materials'; } else { $pageTitle = PageForTitle::find()->where(['title' => $item[0]])->one(); if (empty($pageTitle->id)) { $pageTitle = new PageForTitle(); $pageTitle->title = $item[0]; $pageTitle->save(); } /*$pageTitle = new PageForTitle(); $pageTitle->title = $item[0]; $pageTitle->save();*/ $pageItem->id_page = $pb->id; $pageItem->id_item = $pageTitle->id; $pageItem->item_type = 'zagolovok'; } $pageItem->id_blind = $blind->id; $pageItem->save(); } } } else { } return $this->redirect(['update', 'id' => $blind->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $arr_cat, 'catselect' => $arr_catid, 'materials' => $arr_materials, 'materialselect' => $arr_supl, 'media' => $media, 'img' => $imgages, 'bmt' => $blindMaterialHeader, 'blind' => $blind, 'addMat' => $addMaterials]); } }
/** * @param string $type * @param string $slug * @param int $page * * @return string */ public function actionView($type, $slug, $page = 1) { /* @var $taxonomy Taxonomy */ /* @var $postType PostType */ /* @var $posts Post[] */ /* @var $images Media[] */ /* @var $terms Term[] */ /* @var $mediaSet Media[] */ /* @var $post Post */ $page--; $items = []; $response = Yii::$app->response; $response->headers->set('Content-Type', 'text/xml; charset=UTF-8'); $response->format = $response::FORMAT_RAW; if ($type === 'h') { $item['loc'] = Yii::$app->urlManager->hostInfo . Yii::$app->urlManager->baseUrl; $item['changefreq'] = $this->_option['home']['changefreq']; $item['priority'] = $this->_option['home']['priority']; return $this->renderPartial('home', ['item' => $item]); } elseif ($type === 'p') { $postType = PostType::find()->where(['post_type_slug' => $slug])->one(); $posts = $postType->getPosts()->andWhere(['post_status' => 'publish'])->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all(); foreach ($posts as $post) { $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone'))); $items[$post->id]['loc'] = $post->url; $items[$post->id]['lastmod'] = $lastmod->format('r'); $items[$post->id]['changefreq'] = $this->_option['post_type'][$postType->id]['changefreq']; $items[$post->id]['priority'] = $this->_option['post_type'][$postType->id]['priority']; if ($images = $post->getMedia()->where(['LIKE', 'media_mime_type', 'image/'])->all()) { foreach ($images as $image) { $metadata = $image->getMeta('metadata'); $items[$post->id]['image'][$image->id]['loc'] = $image->uploadUrl . $metadata['media_versions']['full']['url']; $items[$post->id]['image'][$image->id]['title'] = $image->media_title ? $image->media_title : null; $items[$post->id]['image'][$image->id]['caption'] = $image->media_excerpt ? $image->media_excerpt : null; } } } return $this->renderPartial('post-type', ['items' => $items]); } elseif ($type === 'c') { $taxonomy = Taxonomy::find()->where(['taxonomy_slug' => $slug])->one(); $terms = $taxonomy->getTerms()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all(); foreach ($terms as $term) { $post = $term->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one(); if ($post) { $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone'))); $items[$term->id]['loc'] = $term->url; $items[$term->id]['lastmod'] = $lastmod->format('r'); $items[$term->id]['changefreq'] = $this->_option['taxonomy'][$taxonomy->id]['changefreq']; $items[$term->id]['priority'] = $this->_option['taxonomy'][$taxonomy->id]['priority']; } } return $this->renderPartial('taxonomy', ['items' => $items]); } elseif ($type === 'm') { $mediaSet = Media::find()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all(); foreach ($mediaSet as $media) { $lastmod = new \DateTime($media->media_modified, new \DateTimeZone(Option::get('time_zone'))); $items[$media->id]['loc'] = $media->url; $items[$media->id]['lastmod'] = $lastmod->format('r'); $items[$media->id]['changefreq'] = $this->_option['media']['changefreq']; $items[$media->id]['priority'] = $this->_option['media']['priority']; } return $this->renderPartial('media', ['items' => $items]); } return $this->redirect(['/site/not-found']); }
/** * @param AcceptanceTester $I */ public function testComment(AcceptanceTester $I) { $I->wantTo('ensure that media comment works'); $mediaView = MediaViewPage::openBy($I); // $I->see('Test Media', 'h1'); $I->see('Test Media'); $I->amGoingTo('submit media comment form with no data'); $mediaView->submitComment([]); $I->expectTo('see validations error'); $I->see('Name cannot be blank.', '.help-block'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit media comment form with no correct email'); $mediaView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']); $I->expectTo('see that email is not correct'); $I->see('Email is not a valid email address.'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit media comment form with correct data'); $mediaView->submitComment(['comment_author' => 'tester', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'New comment']); $I->expect('new comment saved'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Email cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); MediaComment::deleteAll(['comment_author' => 'tester']); Media::findOne(1)->updateAttributes(['media_comment_count' => '1']); }
/** * @return \yii\db\ActiveQuery */ public function getMedia() { return $this->hasMany(Media::className(), ['media_post_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getMedia() { return $this->hasMany(Media::className(), ['author' => 'id']); }
private static function _mediaDecoder($attributes, $content) { if (isset($attributes['itemno'])) { $itemNo = (int) $attributes['itemno']; } else { $itemNo = null; } $entityType = isset($attributes['object']) ? Entity::mapType($attributes['object']) : null; $refId = isset($attributes['id']) ? $attributes['id'] : null; if (empty($itemNo) || empty($entityType) || empty($itemNo)) { return null; } $params = array(Media::ENCODE_ENTITY => $entityType, Media::ENCODE_ID => $refId, Media::ENCODE_ITEMNO => $itemNo); if (isset($attributes['width'])) { $params[Media::ENCODE_WIDTH] = $attributes['width']; } else { $params[Media::ENCODE_WIDTH] = 770; } if (isset($attributes['height'])) { $params[Media::ENCODE_HEIGHT] = $attributes['height']; } $query = Media::find(); $query->andWhere(['type' => $entityType, 'refId' => $refId, 'itemNo' => $itemNo]); $media = $query->one(); if (empty($media)) { return; } $encoded = $media->getPublishUri($params); $mediaUrl = Url::toRoute(['/media/' . $encoded]); $imgTag = "<img src=\"{$mediaUrl}\" class=\"img-responsive\">"; /* if (!empty($media->caption)) $captionTag = "<figcaption>{$media->caption}</figcaption>"; else $captionTag = ''; */ $str = <<<EOT {$imgTag} EOT; return $str; }
/** * Finds the Media model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param string $media_slug * * @return Media the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelBySlug($media_slug) { if (($model = Media::find()->andWhere(['media_slug' => $media_slug])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }