/** * Запуск видежта */ public function run() { $query = Blog::find()->orderBy(['created_at' => SORT_DESC]); $countQuery = clone $query; $totalCount = $countQuery->count(); $blogModels = $query->limit(3)->all(); return $this->render('index', ['blogModels' => $blogModels]); }
/** * 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 ($id !== null && ($model = Blog::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'title', true); $this->addCondition($query, 'description', true); $this->addCondition($query, 'body', true); $this->addCondition($query, 'status'); $this->addCondition($query, 'category_id'); $this->addCondition($query, 'created_by'); $this->addCondition($query, 'updated_by'); $this->addCondition($query, 'created_at'); $this->addCondition($query, 'updated_at'); return $dataProvider; }
<div class="blog-index-admin"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('<span>' . Yii::t('blog', 'Create {modelClass}', ['modelClass' => 'Блог']) . '</span>', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'title', 'value' => function ($data) { return \yii\helpers\Html::a($data->title, ['view', 'id' => $data->id]); }, 'format' => 'html'], ['attribute' => 'status', 'value' => function ($data) { return Blog::statusOptions($data->status); }, 'filter' => Blog::statusOptions(null), 'options' => ['style' => 'width:150px;']], ['attribute' => 'Category', 'value' => 'category.name'], 'created_at:datetime', 'updated_at:datetime', 'created_by', 'updated_by', ['attribute' => 'Tags', 'value' => function ($data) { foreach ($data->tags as $tag) { $tags .= $tag->title . ', '; } return $tags; }], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['style' => 'width:30px;']]]]); ?> </div>
<div class="blog-form"> <?php $form = ActiveForm::begin(); ?> <div class="row"> <div class="col-xs-9"> <?php echo $form->field($model, 'title', ['options' => ['maxlength' => 255], 'addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-star"></i>']]]); ?> <?php echo $form->field($model, 'description')->widget(\zxbodya\yii2\tinymce\TinyMce::className(), ['language' => 'ru', 'settings' => ['image_class_list' => [['title' => 'responsive', 'value' => 'img-responsive'], ['title' => 'none', 'value' => '']], 'rel_list' => [[title => 'FancyBox', value => 'fancybox'], [title => 'Обычная', value => '']], 'force_br_newlines' => true, 'force_p_newlines' => false, 'forced_root_block' => false, 'height' => 200, 'image_dimensions' => false, 'extended_valid_elements' => 'img[*],div[*]'], 'fileManager' => ['class' => \zxbodya\yii2\elfinder\TinyMceElFinder::className(), 'connectorRoute' => '/blog/el-finder/connector'], 'spellcheckerUrl' => 'http://speller.yandex.net/services/tinyspell']); ?> </div> <div class="col-xs-3"> <?php echo $form->field($model, 'status')->dropDownList(Blog::statusOptions()); ?> <label><?php echo \Yii::t('blog', 'Category'); ?> </label> <?php echo TreeViewInput::widget(['query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Категория'], 'attribute' => 'category_id', 'model' => $model, 'asDropdown' => true, 'multiple' => false, 'fontAwesome' => true, 'rootOptions' => ['label' => '<i class="fa fa-tree"></i>', 'class' => 'text-success']]); ?> <?php echo $form->field($model, 'tagged'); ?> <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']); ?>
?> <?php echo $form->field($model, 'title', ['options' => ['maxlength' => 255], 'addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-star"></i>']]]); ?> <?php echo $form->field($model, 'body')->textarea(); ?> <?php if (!isset($blog_id)) { ?> <?php echo $form->field($model, 'blog_id')->widget(Select2::className(), ['data' => ['' => '--- Select ---'] + Blog::options(), 'options' => ['placeholder' => 'Select a state ...', 'multiple' => FALSE], 'pluginOptions' => ['allowClear' => true]]); ?> <?php } ?> <?php if (!isset($root)) { ?> <?php echo $form->field($model, 'parent')->dropDownList(['' => \Yii::t('app', '--- Select Parent ---')] + Thread::options()); ?> <?php } ?>
/** * @return \yii\db\ActiveQuery */ public function getBlog() { return $this->hasOne(Blog::className(), ['id' => 'blog_id']); }
?> <div class="comment-view widget-container boxed" style="padding: 15px; 0px;"> <div class="inner"> <div class="comment-form"> <?php $form = ActiveForm::begin(['id' => 'comment-form']); ?> <div class="form-inner"> <?php echo $form->field($model, 'title', ['options' => ['maxlength' => 255], 'addon' => ['prepend' => ['content' => '<i class="glyphicon glyphicon-star"></i>']]])->label('Заголовок или Ваше имя'); ?> <?php if (!isset($blog_id)) { ?> <?php echo $form->field($model, 'blog_id')->widget(Select2::className(), ['data' => ["" => "--- Select ---"] + Blog::options(['status' => Blog::STATUS_ACTIVE])]); ?> <?php } ?> <?php if (!isset($blog_id)) { ?> <?php echo $form->field($model, 'status')->dropDownList(Comment::statusOptions()); ?> <?php } ?> <?php echo $form->field($model, 'body')->textArea(['rows' => 10, 'cols' => 30]);