/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::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, 'category_id' => $this->category_id, 'user_id' => $this->user_id, 'images_id' => $this->images_id, 'publication_at' => $this->publication_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'status' => $this->status, 'order' => $this->order]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'prev_img', $this->prev_img]); return $dataProvider; }
public function actionView($slug) { $model = new Blog(); return $this->render('full_post', ['model' => $model->find()->where(['slug' => $slug])->one(), 'action' => 'full']); }
/** * Finds the Blog model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Blog the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Blog::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDelete() { $blog = Blog::findByPk($this->container->request->query('id'), $this->container); return $blog->delete(); }
public function run() { $model = new Blog(); $blog_feed = $model->getBlogFeed($this->item); return $this->render('blog_feed', ['blog_feed' => $blog_feed, 'title' => $this->title, 'line' => $this->line]); }
/** * @return \yii\db\ActiveQuery */ public function getBlogs() { return $this->hasMany(Blog::className(), ['category_id' => 'id']); }
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>