本文整理汇总了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));
}
}
示例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');
}
}