/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Category(); $model->detachBehavior("NestedSetBehavior"); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // Создаем корневую директорию $last_root = Yii::app()->db->createCommand("select root from category order by root desc limit 1")->queryScalar(); if (isset($_POST['Category'])) { $model->attributes = $_POST['Category']; $model->lft = 1; $model->rgt = 2; $model->level = 1; $model->root = $last_root + 1; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }