/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'update' page.
  */
 public function actionCreate($id = null)
 {
     $this->breadcrumbs = array('До и После' => array('/beforeafter/beforeafterrubrics/index'), 'Новая запись');
     $model = new BeforeAfterRubrics();
     $root = BeforeAfterRubrics::getRoot($model);
     $descendants = $root->descendants()->findAll($root->id);
     if (isset($_POST['BeforeAfterRubrics'])) {
         $model = new BeforeAfterRubrics();
         $parent_id = (int) $_POST['BeforeAfterRubrics']['parent_id'];
         $root = BeforeAfterRubrics::model()->findByPk($parent_id);
         $model->attributes = $_POST['BeforeAfterRubrics'];
         if (!$root) {
             //Создаю родительскую категорию
             $result = BeforeAfterRubrics::getRoot(new BeforeAfterRubrics());
             $model->id = (int) $result->id;
         } else {
             $model->appendTo($root);
         }
         if (!empty($model->id)) {
             $this->redirect(array('update', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'root' => $root, 'categories' => $descendants, 'id' => null));
 }