protected function findModel($id)
 {
     if (($model = \plathir\smartblog\backend\models\Categorytree::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #2
0
?>

            <p>
                <?php 
echo Html::a('Create Posts', ['create'], ['class' => 'btn btn-success']);
?>
            </p>
            <?php 
$userModel = new $searchModel->module->userModel();
$user_items = \yii\helpers\ArrayHelper::map($userModel::find()->where('status = 10')->all(), 'id', 'username');
?>

            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'contentOptions' => ['style' => 'width: 7%;']], ['attribute' => 'description', 'contentOptions' => ['style' => 'width: 15%;']], ['attribute' => 'category', 'value' => function ($model) {
    if ($model->category) {
        $category = Category::findOne(['id' => $model->category]);
        if ($category) {
            return $category->name;
        }
    }
}, 'contentOptions' => ['style' => 'width: 15%;'], 'filter' => TreeViewInput::widget(['model' => $searchModel, 'attribute' => 'category', 'showInactive' => true, 'query' => Category::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Categories'], 'asDropdown' => true, 'multiple' => true, 'fontAwesome' => true, 'dropdownConfig' => ['dropdown' => ['style' => 'width:250px']], 'rootOptions' => ['label' => '<i class="fa fa-tree"></i>', 'class' => 'text-success']])], ['attribute' => 'user_created', 'value' => function ($model, $key, $index, $widget) {
    $userModel = new $model->module->userModel();
    return $userModel::findOne(['id' => $model->user_created])->{$model->module->userNameField};
}, 'format' => 'html', 'contentOptions' => ['style' => 'width: 10%;'], 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'user_created', $user_items, ['class' => 'form-control', 'prompt' => 'Select...'])], ['attribute' => 'created_at', 'format' => ['date', 'php:d-m-Y'], 'filter' => DateControl::widget(['model' => $searchModel, 'attribute' => 'created_at', 'name' => 'kartik-date-1', 'value' => 'created_at', 'type' => DateControl::FORMAT_DATE, 'options' => ['layout' => '{picker}{input}']]), 'contentOptions' => ['style' => 'width: 12%;']], ['attribute' => 'user_last_change', 'value' => function ($model, $key, $index, $widget) {
    $userModel = new $model->module->userModel();
    return $userModel::findOne(['id' => $model->user_last_change])->{$model->module->userNameField};
}, 'format' => 'html', 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'user_last_change', $user_items, ['class' => 'form-control', 'prompt' => 'Select...']), 'contentOptions' => ['style' => 'width: 10%;']], ['attribute' => 'updated_at', 'format' => ['date', 'php:d-m-Y'], 'filter' => DateControl::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'name' => 'kartik-date-2', 'value' => 'updated_at', 'type' => DateControl::FORMAT_DATE, 'options' => ['layout' => '{picker}{input}']]), 'contentOptions' => ['style' => 'width: 10%;']], ['attribute' => 'publish', 'value' => function ($model, $key, $index, $widget) {
    return $model->publish == true ? '<span class="label label-success">Published</span>' : '<span class="label label-danger">Unpublished</span>';
}, 'format' => 'html', 'filter' => \yii\bootstrap\Html::activeDropDownList($searchModel, 'publish', ['0' => 'Unpublished', '1' => 'Published'], ['class' => 'form-control', 'prompt' => 'Select...']), 'contentOptions' => ['style' => 'width: 10%;']], ['class' => 'yii\\grid\\ActionColumn', 'contentOptions' => ['style' => 'min-width: 70px;']]]]);
?>