From 3de2cb7a4a5a2fbf0f300822192cc1789b070c3d Mon Sep 17 00:00:00 2001 From: akosse Date: Thu, 23 Jan 2020 16:53:37 +0300 Subject: [PATCH] fix parameters error --- .../modules/card/controllers/UserCardController.php | 12 +++++++----- backend/modules/card/models/UserCard.php | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 1d28e09..4165044 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -49,13 +49,15 @@ class UserCardController extends Controller $total = 0; if(Yii::$app->request->queryParams) - foreach (Yii::$app->request->queryParams as $params) + foreach (Yii::$app->request->queryParams as $params) { + $total = \common\models\UserCard::find()->filterWhere([ - 'fio' => $params['fio'], - 'email' => $params['email'], - 'status' => $params['status'], - 'skills' => $params['skills'], + 'fio' => UserCard::getParameter($params, 'fio'), + 'email' => UserCard::getParameter($params, 'email'), + 'status' => UserCard::getParameter($params, 'status'), + 'skills' => UserCard::getParameter($params, 'skills'), ])->sum('salary'); + } else $total = \common\models\UserCard::find()->sum('salary'); return $this->render('index', [ diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index 8557172..6ffdef5 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -158,4 +158,13 @@ class UserCard extends \common\models\UserCard if ($user_card_array) return "Данные успешно сгенерированы"; else return "Нет данных для генерации"; } + + public static function getParameter($params, $key) + { + try { + return $params[$key]; + } catch (\Exception $e) { + return ''; + } + } }