コード例 #1
0
ファイル: ProductController.php プロジェクト: htom78/XZB2c
 public function actionCreate()
 {
     $this->htmlOption = array('class' => 'icon-head head-products', 'header' => "添加商品", 'button' => array(array('class' => 'scalable save', 'id' => 'form-save', 'header' => '保存')));
     $product = new product_entity();
     $product->seo = new seo();
     $image = new image_entity();
     if (isset($_POST['product'])) {
         $product->attributes = $_POST['product'];
         $product->seo->attributes = $_POST['seo'];
         $image->attributes = $_POST['image'];
         $product->product_def_category_ID = category_entity::resolveDefCategory($_POST['product']['product_category_ID']);
         if ($product->seo->validate()) {
             $product->seo->save();
             $product->product_SEO_ID = $product->seo->SEO_ID;
             if ($product->save()) {
                 category_product::productAddment($product->product_ID, $_POST['product']['product_category_ID']);
                 $image->image_name = $this->uploadCover();
                 $image->image_cover = 1;
                 $image->image_position = 0;
                 $image->image_product_ID = $product->product_ID;
                 $image->save();
                 $this->redirect(array('index'));
             }
         }
         $tree = $this->constructCategoryTree($_POST['product']['product_category_ID']);
     }
     if (!isset($tree)) {
         $tree = $this->constructCategoryTree();
     }
     $this->constructScript('create');
     $this->sideView = 'sidebar/create';
     $this->layout = 'column2';
     $this->render('create', array('model' => $product, 'tree' => $tree, 'image' => $image));
 }