Exemplo n.º 1
0
 public function postAdd()
 {
     $rules = array();
     $rules['name'] = 'required|min:2|unique:goods';
     $rules['barcode'] = 'min:2|unique:goods';
     $rules['unit'] = 'required|integer';
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to('goods/add')->withErrors($validator)->withInput();
     }
     $good = new Good();
     $good->name = Input::get('name');
     $good->barcode = Input::get('barcode');
     $good->purchase = 0;
     $good->sell = 0;
     $good->store = 0;
     $good->damage = 0;
     $good->replacement = 0;
     $good->unit = Input::get('unit');
     $good->save();
     // 日志
     //
     $this->__goodLog($good->id, 0, 'new');
     return Redirect::to('goods')->with('success', '货品添加成功!');
 }
Exemplo n.º 2
0
 /**
  * Создает новую модель товара.
  * Если создание прошло успешно - перенаправляет на просмотр.
  */
 public function actionCreate()
 {
     $model = new Good();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Good'])) {
         $model->attributes = $_POST['Good'];
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CatalogModule.catalog', 'Record was added!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
         }
     }
     $this->render('create', array('model' => $model));
 }