public function actionInfo() { $info = file_get_contents('php://input'); if ($info = json_decode($info, true)) { foreach ($info as $key => $value) { $model = Info::findOne(['key' => $key, 'client_id' => $this->client_user->id]); if (!$model instanceof Info) { $model = new Info(); } $model->key = $key; $model->value = $value; if ($this->client_user instanceof ClientUsers) { $model->client_id = $this->client_user->id; } $model->save(); } } else { throw new HttpException(400, 'Invalid info'); } }
protected function findModel($id) { if (($model = Info::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }