/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BlogPost::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'catalog_id' => $this->catalog_id, 'click' => $this->click, 'user_id' => $this->user_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'surname', $this->surname]);
     return $dataProvider;
 }
 public function actionCatalog()
 {
     if (Yii::$app->request->get('id') && Yii::$app->request->get('id') > 0) {
         $query = BlogPost::find();
         $query->where(['status' => Status::STATUS_ACTIVE, 'catalog_id' => Yii::$app->request->get('id')]);
     } else {
         $this->redirect(['blog/index']);
     }
     if (Yii::$app->request->get('tag')) {
         $query->andFilterWhere(['tags' => Yii::$app->request->get('tag')]);
     }
     if (Yii::$app->request->get('keyword')) {
         //$keyword = '%'.strtr(Yii::$app->request->get('keyword'), array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%';
         $keyword = Yii::$app->request->get('keyword');
         $query->andFilterWhere(['title' => $keyword]);
     }
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['blogPostPageCount'], 'totalCount' => $query->count()]);
     $posts = $query->orderBy('created_at desc')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
 }
Exemple #3
0
 public function run()
 {
     $posts = BlogPost::find()->where(['status' => Status::STATUS_ACTIVE])->orderBy(['click' => SORT_DESC])->limit($this->maxPosts)->all();
     return $this->render('recentPosts', ['title' => $this->title, 'posts' => $posts]);
 }
Exemple #4
0
use yii\widgets\ActiveForm;
use funson86\blog\models\BlogPost;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model backend\modules\blog\models\BlogComment */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="blog-comment-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'post_id')->dropDownList(ArrayHelper::map(BlogPost::find()->all(), 'id', 'title'));
?>

    <?php 
echo $form->field($model, 'content')->textarea(['rows' => 6]);
?>

    <?php 
echo $form->field($model, 'author')->textInput(['maxlength' => 128]);
?>

    <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => 128]);
?>

    <?php