コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $query->with('category', 'type');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'type_id' => $this->type_id, 'views' => $this->views, 'publish_status' => $this->publish_status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'title_seo', $this->title_seo])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'preview', $this->preview])->andFilterWhere(['like', 'content', $this->content]);
     if ($this->meta_description === 'yes') {
         $query->andOnCondition('`meta_description` != ""');
     }
     if ($this->meta_description === 'no') {
         $query->andOnCondition('`meta_description` = ""');
     }
     return $dataProvider;
 }
コード例 #2
0
ファイル: _form.php プロジェクト: esoftslimited/yii2-blog
        <!--Right column START-->
        <div class="col-md-3">
            <div class="panel panel-default">
                <div class="panel-body">

                    <div id="thumbnail-container"><?php 
echo $model->getThumbnailImage('original');
?>
</div>

                    <?php 
echo $form->field($model, 'thumbnail')->widget(FileInput::className(), ['thumb' => 'original', 'template' => '<div class="input-group">{input}<span class="btn-group">{button}{reset-button}</span></div>', 'pasteData' => FileInput::DATA_ID, 'buttonName' => Module::t('main', 'Set thumbnail'), 'imageContainer' => '#thumbnail-container']);
?>

                    <?php 
echo $form->field($model, 'publish_status')->dropDownList(Post::getStatuses());
?>

                    <?php 
if ($model->type->show_category) {
    ?>
                        <?php 
    echo $form->field($model, 'category_id')->dropDownList(Category::getList());
    ?>
                    <?php 
}
?>

                    <?php 
echo $form->field($model, 'alias')->textInput(['maxlength' => 255, 'class' => 'form-control translit-output']);
?>
コード例 #3
0
ファイル: Category.php プロジェクト: esoftslimited/yii2-blog
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPosts()
 {
     return $this->hasMany(Post::className(), ['category_id' => 'id']);
 }
コード例 #4
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #5
0
ファイル: index.php プロジェクト: esoftslimited/yii2-blog
            <div class="col-md-5">
                <?php 
    echo $this->render('_search', ['model' => $searchModel, 'titles' => $titles]);
    ?>
            </div>
        <?php 
}
?>
    </div>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'title', 'format' => 'html', 'value' => function ($model) {
    return Html::a($model->title, ['post/update', 'id' => $model->id]);
}], ['attribute' => 'category_id', 'value' => function ($model) {
    return !empty($model->category) ? $model->category->title : null;
}, 'filter' => Category::getList()], ['attribute' => 'type_id', 'value' => function ($model) {
    return $model->type->title;
}, 'filter' => Type::getList()], ['attribute' => 'meta_description', 'format' => 'html', 'value' => function ($model) {
    $metaDescriptionStatus = !empty($model->meta_description) ? 1 : 0;
    return Helper::booleanIconChoiceArray()[$metaDescriptionStatus];
}, 'filter' => ['yes' => Yii::t('yii', 'Yes'), 'no' => Yii::t('yii', 'No')], 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']], ['attribute' => 'views', 'headerOptions' => ['class' => 'text-center'], 'contentOptions' => ['class' => 'text-center']], ['attribute' => 'publish_status', 'value' => function ($model) {
    return $model->getStatus();
}, 'filter' => Post::getStatuses()], ['header' => Module::t('main', 'Last changes'), 'value' => function ($model) {
    return Yii::$app->formatter->asDatetime($model->getLastChangesTimestamp());
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {delete}', 'buttons' => ['view' => function ($url, $model) {
    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $this->context->getViewPostUrl($model), ['target' => '_blank', 'title' => Module::t('main', 'View post on the site')]);
}]]]]);
?>

</div>