Ejemplo n.º 1
0
 public function actionCreate()
 {
     $this->htmlOption = array('class' => 'icon-head head-products', 'header' => "新建分类", 'button' => array(array('class' => 'scalable save', 'id' => 'category-save', 'header' => '保存')));
     $category = new category_entity();
     $category->seo = new seo();
     if (isset($_GET['parent'])) {
         $category->category_parent_ID = $_GET['parent'];
     }
     if (isset($_POST['category'])) {
         $category->seo->attributes = $_POST['seo'];
         $category->attributes = $_POST['category'];
         if ($category->seo->save()) {
             $category->category_SEO_ID = $category->seo->SEO_ID;
             if (isset($_POST['category']['category_parent_ID']) && $_POST['category']['category_parent_ID'] != null) {
                 $parent = category_entity::model()->findByPk($category->category_parent_ID);
                 $category->category_level = $parent->category_level + 1;
                 $category->category_path = $parent->category_path . ',' . $parent->category_ID;
             } else {
                 $category->category_parent_ID = 0;
                 $category->category_level = 1;
                 $category->category_path = 0;
             }
             if ($category->save()) {
                 $this->redirect(array('update'));
             }
         }
     }
     $this->constructScript();
     $this->sideView = 'sidebar/index';
     $this->layout = 'column2';
     $this->sideData = array('tree' => $this->constructCategoryTree($_GET['parent']));
     $this->render('index', array('model' => $category));
 }