示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $query->orderBy('position DESC, title');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'position' => $this->position]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
示例#2
0
/* @var $searchModel pendalf89\blog\models\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Module::t('main', 'Categories');
$this->params['breadcrumbs'][] = ['label' => Module::t('main', 'Blog'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <p>
        <?php 
echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Module::t('main', 'New category'), ['create'], ['class' => 'btn btn-success']);
?>

        <?php 
echo Html::a('<span class="glyphicon glyphicon-tree-deciduous"></span> ' . Module::t('main', 'Category tree'), ['tree'], ['class' => 'btn btn-primary']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'parent_id', 'value' => function ($model) {
    return $model->getParentTitle();
}, 'filter' => Category::getList()], 'title', 'alias', 'position', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
示例#3
0
 /**
  * Check that blog just installed
  * @return bool
  */
 public static function isJustInstalled()
 {
     $types = Type::find()->all();
     $categories = Category::find()->all();
     return empty($types) || empty($categories) ?: false;
 }
示例#4
0
?>
</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']);
?>

                    <?php 
echo $form->field($model, 'views')->textInput();
?>

                    <?php 
if (!$model->isNewRecord) {
示例#5
0
 /**
  * @return null|string parent title
  */
 public function getParentTitle()
 {
     $model = Category::findOne($this->parent_id);
     return !empty($model) ? $model->title : null;
 }
示例#6
0
文件: Post.php 项目: GAMITG/yii2-blog
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
示例#7
0
/* @var $model pendalf89\blog\models\Category */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="category-form">

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

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255, 'class' => 'form-control translit-input']);
?>

    <?php 
echo $form->field($model, 'parent_id')->dropDownList(Category::getList($model->id), ['prompt' => Module::t('main', 'Select parent category')]);
?>

    <?php 
echo $form->field($model, 'alias')->textInput(['maxlength' => 255, 'class' => 'form-control translit-output']);
?>

    <?php 
echo $form->field($model, 'position')->textInput()->hint(Module::t('main', 'Number of position on sorting. The higher the number, the higher category is to issue.'));
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Module::t('main', 'Create') : Module::t('main', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>
示例#8
0
            <div class="col-md-4">
                <?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>
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }