Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new GoodsType();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GoodsType'])) {
         $model->attributes = $_POST['GoodsType'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->cat_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #2
0
 /**
  * 类型添加
  */
 public function actionCreate()
 {
     if ($_POST) {
         $GoodsType = new GoodsType();
         $GoodsType->attributes = $this->post('Type');
         $type_brand_attributes = $this->post('TypeBrand');
         //商品类型主表修改
         $result = $GoodsType->save();
         if (!$result) {
             $GoodsType = new GoodsType();
             $this->message('error', CHtml::errorSummary($GoodsType), $this->createUrl('index'));
         }
         $type_id = Yii::app()->db->getLastInsertID();
         //类型-品牌
         if ($type_brand_attributes) {
             $TypeBrand = new TypeBrand();
             $result = $TypeBrand->brand_type_update($type_id, $type_brand_attributes);
             if (!$result) {
                 $this->message('error', CHtml::errorSummary($TypeBrand), $this->createUrl('index'));
             }
         }
         //类型-扩展属性
         $type_props_attributes = $this->post('TypeProps');
         if (isset($type_props_attributes['props_id']) && $type_props_attributes['props_id']) {
             $GoodsTypePropsRelation = new GoodsTypePropsRelation();
             $result = $GoodsTypePropsRelation->props_update($type_id, $type_props_attributes['props_id']);
             if (!$result) {
                 $this->message('error', CHtml::errorSummary($GoodsTypePropsRelation), $this->createUrl('index'));
             }
         }
         //类型-规格
         $type_props_spec = $this->post('Spec');
         if (isset($type_props_spec['spec_id']) && $type_props_spec['spec_id']) {
             $GoodsTypeSpec = new GoodsTypeSpec();
             $result = $GoodsTypeSpec->spec_update($type_id, $type_props_spec['spec_id']);
             if (!$result) {
                 $this->message('error', CHtml::errorSummary($GoodsTypeSpec), $this->createUrl('index'));
             }
         }
         $this->message('success', '创建成功', $this->createUrl('index'));
     }
     //品牌列表
     $model['brand_list'] = Brand::model()->findAll('disabled = :disabled', array(':disabled' => 'false'));
     //规格
     $model['spec_list'] = Specification::model()->findAll('disabled = :disabled', array(':disabled' => 'false'));
     $this->render('create', array('model' => $model));
 }