public function actionIndex() { $settings = Yii::$app->settings; $num_post = $settings->get('blog.number_posts'); $query = Blog::getPublishedPosts(); $countQuery = clone $query; $pages = new Pagination(['defaultPageSize' => $num_post, 'totalCount' => $countQuery->count()]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); // var_dump($models);exit; return $this->render('index', ['blog_post' => $models, 'pages' => $pages, 'category' => BlogCategory::find()->where(['status' => BlogCategory::STATUS_PUBLISH])->all(), 'action' => 'short']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlogCategoryModel::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, 'parent_id' => $this->parent_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status, 'order' => $this->order]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'prev_img', $this->prev_img]); return $dataProvider; }
/* @var $form yii\widgets\ActiveForm */ ?> <div class="blog-form"> <?php $form = ActiveForm::begin([ 'options' => [ 'enctype' => 'multipart/form-data', ] ] ); ?> <div class="row"> <div class="col-lg-6"> <?= $form->field($model, 'category_id')->widget(Select2::classname(), [ 'language' => 'ru', 'value' => 0, 'data' => ArrayHelper::map(BlogCategory::find()->all(), 'id', 'name'), 'options' => [ 'placeholder' => 'Select provinces ...', ], 'pluginOptions' => [ 'allowClear' => TRUE ], ]); ?> </div> <div class="col-lg-6"> <?php // On our echo $form->field($model, 'tagNames')->widget(SelectizeTextInput::className(), [ // calls an action that returns a JSON object with matched // // tags
/** * Finds the BlogCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BlogCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BlogCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(BlogCategory::className(), ['id' => 'category_id']); }
use kartik\select2\Select2; use dosamigos\fileinput\BootstrapFileInput; /* @var $this yii\web\View */ /* @var $model app\modules\blog\models\Blog */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="blog-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <div class="row"> <div class="col-lg-6"> <?php echo $form->field($model, 'category_id')->widget(Select2::classname(), ['language' => 'ru', 'value' => 0, 'data' => ArrayHelper::map(BlogCategory::find()->all(), 'id', 'name'), 'options' => ['placeholder' => 'Select provinces ...'], 'pluginOptions' => ['allowClear' => TRUE]]); ?> </div> <div class="col-lg-6"> <?php // On our echo $form->field($model, 'tagNames')->widget(SelectizeTextInput::className(), ['loadUrl' => ['blog-tags/list'], 'options' => ['class' => 'form-control'], 'clientOptions' => ['plugins' => ['remove_button'], 'valueField' => 'name', 'labelField' => 'name', 'searchField' => ['name'], 'create' => TRUE]])->hint('Use commas to separate tags'); ?> </div> <div class="col-lg-6"> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true])->hint('заголовок'); ?> <?php echo $form->field($model, 'id')->hiddenInput()->label(false);
use app\modules\blog\models\Blog; /* @var $this yii\web\View */ /* @var $searchModel app\modules\admin\models\search\BlogSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Blogs'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="blog-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Blog', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'options' => ['width' => '50']], ['filter' => ArrayHelper::map(BlogCategory::find()->all(), 'id', 'name'), 'attribute' => 'category_id', 'value' => 'category.name'], ['filter' => ArrayHelper::map(User::find()->all(), 'id', 'username'), 'attribute' => 'user_id', 'value' => 'user.username'], ['class' => LinkColumn::className(), 'attribute' => 'title', 'value' => function ($data) { return \yii\helpers\StringHelper::truncate($data->title, 30, '...'); }, 'options' => ['width' => '250', 'title' => 'title']], 'slug', ['class' => SetColumn::className(), 'filter' => Blog::getStatusesArray(), 'attribute' => 'status', 'name' => 'statusName', 'cssCLasses' => [Blog::STATUS_PUBLISH => 'success', Blog::STATUS_UNPUBLISH => 'default']], ['attribute' => 'publication_at', 'format' => ['date', 'd MMMM yyyy HH:mm']], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>