} }); } }); JS ); ?> <div class="container"> <div class="page-header"> <h1>Статьи</h1> </div> <?php echo \yii\grid\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \app\models\Article::query()->orderBy(['date_insert' => SORT_DESC]), 'pagination' => ['pageSize' => 20]]), 'columns' => ['id', ['header' => 'Картинка', 'content' => function ($item) { if ($item['image']) { return Html::a(Html::img($item['image'], ['class' => 'thumbnail', 'width' => 80, 'style' => 'margin-bottom: 0px;']), ['admin_article/edit', 'id' => $item['id']]); } else { if ($item['video']) { $video = $item['video']; $video = new \cs\services\Url($video); $video = explode('/', $video); $video = $video[count($video) - 1]; return Html::a($video, ['admin_article/edit', 'id' => $item['id']]); } } }], ['header' => 'Название', 'content' => function ($item) { return Html::a($item['header'], ['admin_article/edit', 'id' => $item['id']]); }], 'date_insert:datetime:Дата добавления', ['header' => 'Удалить', 'content' => function ($item) { return Html::button('Удалить', ['class' => 'btn btn-danger btn-xs buttonDelete', 'data-id' => $item['id']]);
public function actionSearch() { $term = self::getParam('term'); $items = Article::query(['like', 'content', $term])->orWhere(['like', 'header', $term])->all(); return $this->render(['list' => $items]); }
<input type="text" name="term" value="Введите слово ..." onFocus="this.value=''" onBlur="this.value='Введите слово ...'"/> </form> </div> </div> <!-- #first .widget-area --> <div id="second" class="widget-area"> <div class="widget widget_archive"> <h3 class="widget-title">Архивы</h3> <?php $min = \app\models\Article::query()->select('min(date_insert)')->scalar(); $dateMin = new DateTime($min); $dateNow = new DateTime(); $rows = \app\models\Article::query()->select(['count(*) as c1', 'YEAR(date) as year', 'MONTH(date) as month'])->groupBy(['YEAR(date)', 'MONTH(date)'])->orderBy(['YEAR(date)' => SORT_DESC, 'MONTH(date)' => SORT_DESC])->all(); /** @var int $max максиальный месяц с годом 1-12 */ $max = $rows[0]['year'] * 12 + ($rows[0]['month'] - 1); $min = $rows[count($rows) - 1]['year'] * 12 + ($rows[count($rows) - 1]['month'] - 1); ?> <ul> <?php for ($i = $max; $i >= $min; $i--) { ?> <?php $month = $i % 12; if ($month == 0) { $month = 11; } $monthZero = $month + 1; if ($monthZero < 10) {
public function actionArticle($category, $year, $month, $day, $id) { $item = Article::find(['id_string' => $id, 'DATE(date_insert)' => $year . $month . $day]); if (is_null($item)) { throw new Exception('Нет такой статьи'); } $categoryObject = UnionCategory::find(['id_string' => $category]); $item->incViewCounter(); $nearList = Article::getByTreeNodeIdQuery($categoryObject->getId())->andWhere(['not in', 'id', $item->getId()])->limit(3)->all(); if (count($nearList) == 0) { $nearList = Article::query()->select('id,header,id_string,image,view_counter,description,content,date_insert')->orderBy(['date_insert' => SORT_DESC])->andWhere(['not in', 'id', $item->getId()])->limit(3)->all(); } return $this->render(['item' => $item->getFields(), 'category' => $category, 'nearList' => $nearList, 'breadcrumbs' => $categoryObject->getBreadCrumbs([$item->getField('header')])]); }
public function actionIndex() { return $this->render(['items' => Article::query()->orderBy(['date_insert' => SORT_DESC])->all()]); }