public function actionCreate()
 {
     $err = true;
     $this->breadcrumbs = array('Теги' => array('index'), 'Создать');
     $model = new Category();
     if (isset($_POST['Category'])) {
         $model->attributes = $_POST['Category'];
         if ($model->validate()) {
             if (!empty($model->parent_id)) {
                 $parent = $this->loadModel($model->parent_id);
                 if ($model->appendTo($parent)) {
                     $model->refresh();
                     $err = false;
                 }
             } else {
                 if ($model->saveNode()) {
                     $err = false;
                 }
             }
             if ($err) {
                 $this->addFlashMessage($model->errors, 'error');
             } else {
                 $this->redirect(Yii::app()->createAbsoluteUrl('/admin/tags'));
             }
         } else {
             $this->addFlashMessage($model->errors, 'error');
         }
     }
     $this->render('_form', array('model' => $model));
 }
    public function actionCreate() {
    
        $err = true;

        $model = new Category();
        if (isset($_POST['Category'])) {
            $model->attributes = $_POST['Category'];

            if ($model->validate()) {

                if (!empty($model->parent_id)) {
                    
                    $parent = $this->loadModel($model->parent_id);
                    if ($model->appendTo($parent)) {
                        $model->refresh();
                        $err = false;
                    }

                } else {
                    if($model->saveNode()   && $model->storeTypeAttributes(Yii::app()->getRequest()->getPost('attributes', []))){
                        $err = false;
                    }
                }

                if ($err) {
                    $this->addFlashMessage($model->errors,'error');
                } else {
                    $this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/default'));
                }
            } else {
                $this->addFlashMessage($model->errors,'error');
            }
        }

        $this->render('_form', array('model' => $model));
    }
 /**
  * @param Category $untouchedCategory1
  * @param Category $untouchedCategory2
  */
 protected function afterManyMany($untouchedCategory1, $untouchedCategory2)
 {
     $this->assertEquals('untouched1', $untouchedCategory1->name);
     $this->assertEquals(0, count($untouchedCategory1->posts));
     $untouchedCategory1->refresh();
     $this->assertEquals('untouched1', $untouchedCategory1->name);
     $this->assertEquals(0, count($untouchedCategory1->posts));
     $this->assertEquals('untouched2', $untouchedCategory2->name);
     $this->assertEquals(9, count($untouchedCategory2->posts));
     $untouchedCategory2->refresh();
     $this->assertEquals('untouched2', $untouchedCategory2->name);
     $this->assertEquals(9, count($untouchedCategory2->posts));
 }
 /**
  * test adding null values to MANY_MANY pk values
  *
  * @dataProvider manymanyData
  */
 public function testManyManyNulls($postsAsPk, $modulo, $config, $transactional)
 {
     $this->setConfig($config);
     $this->startTransaction($transactional);
     if ($postsAsPk) {
         // first with pk data
         $posts = $this->getPosts(10, true);
         for ($n = 1; $n < 10; $n++) {
             if ($n % $modulo == 0) {
                 $posts[$n] = $posts[$n]->id;
             }
         }
     } else {
         $posts = $this->getPosts(10, true);
         // second with object data
     }
     $posts[2] = null;
     $posts[5] = null;
     list($un1, $un2) = $this->beforeManyMany();
     // begin real test
     $category = new Category();
     $category->name = 'my new cat';
     $this->assertEquals(array(), $category->posts);
     $category->save();
     $this->assertEquals(array(), $category->posts);
     $category->save();
     $this->assertEquals(0, count($category->posts));
     $category->posts = $posts;
     $this->assertEquals(9, count($category->posts));
     $category->save();
     $this->assertEquals(9, count($category->posts));
     $category->refresh();
     $this->assertEquals(7, count($category->posts));
     $posts = $category->posts;
     // set some records to null
     $posts[1] = null;
     $posts[3] = null;
     $this->assertEquals(7, count($category->posts));
     $category->posts = $posts;
     $this->assertEquals(7, count($category->posts));
     $category->save();
     $this->assertEquals(7, count($category->posts));
     $category->refresh();
     $this->assertEquals(5, count($category->posts));
     // end real test, checking untouched
     $this->afterManyMany($un1, $un2);
     $this->endTransaction($transactional);
 }