/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = Yii::createObject(Post::className()); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @param $slug * @return array|null|Post * @throws NotFoundHttpException */ public function findBySlug($slug) { /** @var PostQuery $query */ $query = Post::find(); $query->published()->bySlug($slug); if (($model = $query->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'short_text')->widget(CKEditor::className(), ['editorOptions' => ElFinder::ckeditorOptions('elfinder-backend', ['preset' => 'basic'])]); ?> <?php echo $form->field($model, 'text')->widget(CKEditor::className(), ['editorOptions' => ElFinder::ckeditorOptions('elfinder-backend')]); ?> <?php echo $form->field($model, 'slug')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'status')->dropDownList(Post::getStatuses()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('blog', 'Create') : Yii::t('blog', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
?> <div class="blog-post-index"> <div class="row"> <div class="col-lg-12"> <h1 class="page-header"><?php echo Html::encode($this->title); ?> </h1> </div> </div> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('blog', 'Create Blog Post'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], 'id', 'title', 'slug', ['filter' => Post::getStatuses(), 'attribute' => 'status', 'value' => 'statusTitle'], 'created_at:datetime', 'updated_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{duplicate} {view} {update} {delete}', 'buttons' => ['duplicate' => function ($url, $model, $key) { $options = ['title' => Yii::t('blog', 'Duplicate'), 'aria-label' => Yii::t('blog', 'Duplicate'), 'data-pjax' => '0']; return Html::a('<span class="glyphicon glyphicon-duplicate"></span>', $url, $options); }]]]]); ?> </div>