/** * Updates an existing ArticleCategory 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); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->noParents()->all()]); } }
/** * Updates an existing Article 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); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'ads' => Ad::find()->all(), 'articles' => Article::find()->all()]); } }
/** * Updates an existing ArticleCategory 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); $categories = ArticleCategory::find()->noParents()->andWhere(['not', ['id' => $id]])->all(); $categories = ArrayHelper::map($categories, 'id', 'title'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::find(); if (!\Yii::$app->user->can('administrator')) { $query->forDomain(); } $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'domain_id' => $this->domain_id]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::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]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied. * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = ArticleCategory::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 30]]); $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * @param string $category * @return string */ public function actionIndex($category) { $model = ArticleCategory::find()->andWhere(['slug' => $category])->one(); if (!$model) { throw new NotFoundHttpException(); } //Мета-теги foreach (['description', 'keywords'] as $name) { $attr = 'meta_' . $name; \Yii::$app->view->registerMetaTag(['name' => $name, 'content' => strlen($model->{$attr}) > 0 ? $model->{$attr} : Yii::$app->keyStorage->get('frontend.' . $attr)], $name); } $searchModel = new ArticleSearch(); $searchModel->category_id = $model->id; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->sort = ['defaultOrder' => ['created_at' => SORT_DESC]]; return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionIndex() { $catID = Yii::$app->request->get('category'); // Вывести список статей $pageSize = 9; $query = Article::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => $pageSize]); if ($catID) { $models = $query->offset($pages->offset)->where(['article_category' => $catID])->orderBy('created_at DESC')->limit($pages->limit)->all(); } else { $models = $query->offset($pages->offset)->orderBy('created_at DESC')->limit($pages->limit)->all(); } $modelLastArticle = Article::find()->orderBy('id DESC')->limit(3)->all(); $modeMostWatched = Article::find()->orderBy('view DESC')->limit(3)->all(); $ArticleCategoryModel = ArticleCategory::find()->leftJoin('article', '`article`.`article_category` = `article_category`.`id`')->where(['<>', 'article.article_category', 111])->with('article')->all(); return $this->render('index', ['model' => $models, 'modelLastArticle' => $modelLastArticle, 'modeMostWatched' => $modeMostWatched, 'pages' => $pages, 'pageSize' => $pageSize, 'ArticleCategoryModel' => $ArticleCategoryModel]); }
/** * Gets used category switches * @return array */ protected function getCategoryBoxes() { return $this->item_id ? ArticleCategory::find()->select('category_id')->andWhere(['article_id' => $this->item_id])->column() : [Category::getMainCategory($this->language_id)]; }
echo StringHelper::truncate($article->description, 20, '...'); ?> </p> </li> <?php } ?> </ul> <!-- End Latest Links --> <div class="headline-v2"><h2>标签</h2></div> <!-- Tags v2 --> <ul class="list-inline tags-v2 margin-bottom-50"> <?php foreach (\common\models\ArticleCategory::find()->all() as $articleCat) { ?> <li><?php echo Html::a($articleCat->title, ['index', 'ArticleSearch[category_id]' => $articleCat->id]); ?> </li> <?php } ?> </ul> <!-- End Tags v2 --> </div> <!-- End Blog Sidebar --> </div> </div> </div>
/** * Updates an existing Article model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $firstModel = $this->findModel($id); foreach (Yii::$app->params['availableLocales'] as $key => $value) { $currentModel = Article::getLocaleInstance($key); $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one(); $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id); if (!empty($dataModel->domain)) { $dataModel->domain = explode(',', $dataModel->domain); } $models[$key] = $dataModel; if (!$models[$key]) { $currentModel->attributes = $firstModel->attributes; $currentModel->attachments = $firstModel->attachments; $currentModel->thumbnail = $firstModel->thumbnail; $currentModel->image = $firstModel->image; $currentModel->categoriesList = $firstModel->categoriesList; //$currentModel->video = $firstModel->video; $currentModel->locale_group_id = $firstModel->locale_group_id; $currentModel->locale = $key; $currentModel->title = 'title ' . $key . ' ' . time(); $currentModel->slug = ''; $models[$key] = $currentModel; } } $model = new MultiModel(['models' => $models]); if ($model->load(Yii::$app->request->post()) && Article::multiSaveUpdate($model)) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]); } }
/** * Generate menu items for yii\widgets\Menu * * @param null|array $models * @return array */ public static function getMenuItems(array $models = null) { $items = []; if ($models === null) { $models = ArticleCategory::find()->where(['parent_id' => null])->with('childs')->orderBy(['id' => SORT_ASC])->active()->all(); } foreach ($models as $model) { $items[] = ['url' => ['article/category', 'slug' => $model->slug], 'label' => $model->title, 'items' => self::getMenuItems($model->childs)]; } return $items; }
use common\grid\EnumColumn; use common\models\ArticleCategory; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\ArticleSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'Articles'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="article-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => 'Article']), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'grid-view table-responsive'], 'columns' => ['id', 'slug', 'title', ['attribute' => 'category_id', 'value' => function ($model) { return $model->category ? $model->category->title : null; }, 'filter' => ArrayHelper::map(ArticleCategory::find()->all(), 'id', 'title')], ['attribute' => 'created_by', 'value' => function ($model) { return $model->author->username; }], ['class' => EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('backend', 'Not Published'), Yii::t('backend', 'Published')]], 'published_at:datetime', 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\ActiveForm; use common\models\User; use common\models\ArticleCategory; /* @var $this yii\web\View */ /* @var $model common\models\ArticlesSearch */ /* @var $form yii\widgets\ActiveForm */ $authors = User::find()->all(); $items = ArrayHelper::map($authors, 'id', 'username'); $params = ['prompt' => 'Укажите автора']; $category = ArticleCategory::find()->all(); $categoryItem = ArrayHelper::map($category, 'id', 'title'); $categoryParams = ['prompt' => 'Укажите категорию']; ?> <div class="articles-search"> <?php $form = ActiveForm::begin(['action' => ['articles'], 'method' => 'get']); ?> <?php // $form->field($model, 'id') ?> <?php echo $form->field($model, 'title'); ?>
use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\ArticleSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'Articles'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="article-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => 'Article']), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'slug', 'title', ['attribute' => 'category_id', 'value' => function ($model) { return $model->category ? $model->category->title : null; }, 'filter' => \yii\helpers\ArrayHelper::map(\common\models\ArticleCategory::find()->all(), 'id', 'title')], ['attribute' => 'author_id', 'value' => function ($model) { return $model->author->username; }], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('backend', 'Not Published'), Yii::t('backend', 'Published')]], 'published_at:datetime', 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>
<?php use yii\bootstrap\Html; use yii\grid\GridView; use yii\helpers\ArrayHelper; use common\models\ArticleCategory; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\ArticleCategorySearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'Article categories'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="article-category-index"> <p> <?php echo Html::a(Yii::t('backend', 'Create article category'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['title', 'comment', ['attribute' => 'parent_id', 'value' => function ($model) { return $model->parent ? $model->parent->title : null; }, 'filter' => ArrayHelper::map(ArticleCategory::find()->noParents()->all(), 'id', 'title')], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { return $model->status ? '<span class="glyphicon glyphicon-ok text-success"></span>' : '<span class="glyphicon glyphicon-remove text-danger"></span>'; }, 'filter' => [ArticleCategory::STATUS_DRAFT => Yii::t('backend', 'Not active'), ArticleCategory::STATUS_ACTIVE => Yii::t('backend', 'Active')]], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>