コード例 #1
0
 /**
  * Finds the Type model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Type the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Type::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
ファイル: TypeSearch.php プロジェクト: pendalf89/yii2-blog
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Type::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'show_category' => $this->show_category]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: _new.php プロジェクト: pendalf89/yii2-blog
?>
<!---->
<!--            --><?php 
//= Html::submitButton('<span class="glyphicon glyphicon-plus"></span> '
//                . Module::t('main', 'Add'),
//                ['class' => 'btn btn-success'])
?>
<!---->
<!--        --><?php 
//= Html::endForm()
?>

        <?php 
$form = ActiveForm::begin(['action' => ['post/create'], 'method' => 'get', 'layout' => 'inline']);
?>

        <?php 
echo $form->field($model, 'type_id', ['inputTemplate' => '<div class="input-group"><span class="input-group-addon">' . Module::t('main', 'Post type') . '</span>{input}</div>'])->dropDownList(Type::getList());
?>

        <div class="form-group">
            <?php 
echo Html::submitButton('<span class="glyphicon glyphicon-plus"></span> ' . Module::t('main', 'Add'), ['class' => 'btn btn-success']);
?>
        </div>

        <?php 
ActiveForm::end();
?>
    </div>
</div>
コード例 #4
0
ファイル: Helper.php プロジェクト: pendalf89/yii2-blog
 /**
  * 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;
 }
コード例 #5
0
ファイル: Post.php プロジェクト: GAMITG/yii2-blog
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getType()
 {
     return $this->hasOne(Type::className(), ['id' => 'type_id']);
 }
コード例 #6
0
ファイル: index.php プロジェクト: pendalf89/yii2-blog
            <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>