public function actionIndex() { $model = new Nscategory(); if (Yii::$app->request->isAjax) { echo 'Ajax'; } if (Yii::$app->request->isPjax) { echo 'Pjax'; } if (Yii::$app->request->isPost) { echo 'Post'; $model = new Nscategory(); $model->load(Yii::$app->request->post()); if ($model->validate()) { if (Nscategory::find()->roots()->count() <= 0) { $root = new Nscategory(['name' => 'Основная']); $root->makeRoot(); } $root = Nscategory::find()->roots()->one(); $model->appendTo($root); } $model = new Nscategory(); // reset model } return $this->render('index', ['model' => $model]); }
<p> <?php echo Html::a(Yii::t('app', 'Создать {modelClass}', ['modelClass' => 'Nscategory']), ['create'], ['class' => 'btn btn-success']); ?> </p> <!-- Render create form --> <?php echo $this->render('//site/_form', ['model' => $model]); ?> <div class="row"> <div class="col-lg-12"> <?php Pjax::begin(['id' => 'nsitems']); ?> <?php echo sibds\widgets\Nestable::widget(['autoQuery' => \app\models\Nscategory::find(), 'rootable' => false]); ?> <?php Pjax::end(); ?> </div> </div> </div>