本文整理汇总了PHP中app\models\Item::findAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::findAll方法的具体用法?PHP Item::findAll怎么用?PHP Item::findAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Item
的用法示例。
在下文中一共展示了Item::findAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
/**
* Lists all BillItem models.
* @return mixed
*/
public function actionIndex()
{
if (isset($_POST['hasEditable']) && $_POST['hasEditable'] == 1) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (isset($_POST['item'], $_POST['quantity_user'])) {
if (!isset(Yii::$app->session['item'])) {
Yii::$app->session['item'] = [];
}
$item = Yii::$app->session['item'];
$item[$_POST['item']] = $_POST['quantity_user'];
Yii::$app->session['item'] = $item;
return ['output' => $_POST['quantity_user'], 'message' => ''];
} else {
return ['output' => '', 'message' => 'Validation error'];
}
} elseif (isset($_POST['iks'], $_POST['bks'], $_POST['assign_mode'])) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
//Create assignment
if ($_POST['assign_mode'] == 1) {
$items = Item::findAll($_POST['iks']);
$bill = Bill::findOne($_POST['bks'][0]);
$billItem = null;
$transaction = Bill::getDb()->beginTransaction();
try {
foreach ($items as $item) {
$billItem = BillItem::find()->where(['item_id' => $item->id, 'bill_id' => $bill->id])->one();
if ($billItem == null) {
$billItem = new BillItem();
$billItem->bill_id = $bill->id;
$billItem->item_id = $item->id;
}
$itemSession = Yii::$app->session['item'];
$oldQuantity = $billItem->quantity;
$billItem->quantity = $itemSession[$item->id];
if ($oldQuantity > $billItem->quantity) {
$item->quantity += $billItem->quantity;
} elseif ($oldQuantity < $billItem->quantity) {
$item->quantity -= $billItem->quantity;
}
$item->save(false);
if (!$billItem->save(false)) {
throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($billItem->tableName())), 'msj' => print_r($billItem->getErrors(), true)]), 500);
}
}
$transaction->commit();
Yii::$app->session['item'] = [];
return ['error' => false, 'message' => Yii::t('app', 'Saved')];
} catch (\Exception $e) {
$transaction->rollBack();
return ['error' => true, 'message' => print_r($e, true)];
}
}
}
$searchModel = new BillSearch();
$dataProvider = $searchModel->searchWithItem(Yii::$app->request->queryParams);
$itemSearchModel = new ItemSearch();
$itemDataProvider = $itemSearchModel->searchWithItem(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'itemSearchModel' => $itemSearchModel, 'itemDataProvider' => $itemDataProvider]);
}