当前位置: 首页>>代码示例>>PHP>>正文


PHP Inventory::getErrors方法代码示例

本文整理汇总了PHP中Inventory::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Inventory::getErrors方法的具体用法?PHP Inventory::getErrors怎么用?PHP Inventory::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Inventory的用法示例。


在下文中一共展示了Inventory::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionInventory

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionInventory($item_id)
 {
     $model = $this->loadModel($item_id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Item'])) {
         $model->attributes = $_POST['Item'];
         if (empty($_POST['Item']['items_add_minus'])) {
             $valid = false;
             $model->addError('items_add_minus', 'Cannot be blank.');
         } elseif (empty($_POST['Item']['inv_comment'])) {
             $valid = false;
             $model->addError('inv_comment', 'Cannot be blank.');
         } else {
             $new_quantity = $_POST['Item']['items_add_minus'];
             $valid = $model->validate();
         }
         if ($valid) {
             $transaction = $model->dbConnection->beginTransaction();
             try {
                 $cur_quantity = $model->quantity;
                 $model->quantity = $cur_quantity + $new_quantity;
                 if ($model->save()) {
                     //Ramel Inventory Tracking
                     $inventory = new Inventory();
                     $sale_remarks = $_POST['Item']['inv_comment'];
                     $inventory->trans_items = $model->id;
                     $inventory->trans_user = Yii::app()->user->id;
                     $inventory->trans_comment = $sale_remarks;
                     $inventory->trans_inventory = $new_quantity;
                     $inventory->trans_date = date('Y-m-d H:i:s');
                     if (!$inventory->save()) {
                         $transaction->rollback();
                         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                         echo CJSON::encode(array('status' => 'falied', 'div' => "<div class=alert alert-info fade in> Something wrong! </div>" . Yii::app()->user->id . var_dump($inventory->getErrors())));
                         Yii::app()->end();
                     }
                     $transaction->commit();
                     //Yii::app()->clientScript->scriptMap['jquery.js'] = false;
                     echo CJSON::encode(array('status' => 'success', 'div' => "<div class=alert alert-info fade in> Successfully updated ! </div>"));
                     Yii::app()->end();
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 print_r($e);
             }
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         $cs = Yii::app()->clientScript;
         $cs->scriptMap = array('jquery.js' => false, 'bootstrap.js' => false, 'jquery.min.js' => false, 'bootstrap.notify.js' => false, 'bootstrap.bootbox.min.js' => false);
         Yii::app()->clientScript->scriptMap['*.js'] = false;
         echo CJSON::encode(array('status' => 'render', 'div' => $this->renderPartial('_inventory', array('model' => $model), true, false)));
         Yii::app()->end();
     } else {
         $this->render('_inventory', array('model' => $model));
     }
 }
开发者ID:soklux,项目名称:bakou-pos-apsara,代码行数:62,代码来源:ItemController.php

示例2: actionEditableCreator

 public function actionEditableCreator()
 {
     if (isset($_POST['Inventory'])) {
         $model = new Inventory();
         $model->attributes = $_POST['Inventory'];
         if ($model->save()) {
             echo CJSON::encode($model->getAttributes());
         } else {
             $errors = array_map(function ($v) {
                 return join(', ', $v);
             }, $model->getErrors());
             echo CJSON::encode(array('errors' => $errors));
         }
     } else {
         throw new CHttpException(400, 'Invalid request');
     }
 }
开发者ID:schmunk42,项目名称:yii-sakila-crud,代码行数:17,代码来源:InventoryController.php


注:本文中的Inventory::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。