public function getContragentCod() { $user = User::findOne($this->user_id); if (!empty($user)) { return $user->cod; } else { return '(пусто)'; } }
public function testSaveNewPassword() { /** @var User $model */ $model = User::findOne($this->users[0]['id']); $model->scenario = User::SCENARIO_ADMIN_UPDATE; $model->newPassword = '******'; $model->newPasswordRepeat = 'new-password'; expect('model is saved', $model->save())->true(); expect('password is correct', $model->validatePassword('new-password'))->true(); }
public function actionUpdate() { if (\Yii::$app->request->isGet) { $model = User::findOne(\Yii::$app->request->get('id')); if (!$model) { jump_error('数据不存在!', '/'); } } else { if (\Yii::$app->request->isPost) { $model = new User(); $post = \Yii::$app->request->post(); if ($model->updateOne($post[$model->formName()]['id'], $post)) { jump_success('修改成功!'); } else { jump_error('修改失败!'); } } } return $this->render('update', ['model' => $model]); }
/** * 更新一个用户的信息 * * @param $id * @param $params * @return bool */ public function updateOne($id, $params) { $model = User::findOne($id); $model->scenario = 'update'; if ($model->load($params) && $model->validate()) { return $model->save(); } return false; }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 配置用户权限组 * * @return string */ public function actionAssign_ment_edit() { $model = new Auth_assignment(); if (\Yii::$app->request->isGet) { $user_id = \Yii::$app->request->get('user_id'); if (!$user_id || !User::find($user_id)) { jump_error(t_arr('app', ['data', 'does not', 'exists'], '', '!')); } //角色列表 $assignMents = $model->getAssignmentByUserid($user_id); $assignMentSelectArray = []; if (is_array($assignMents) && count($assignMents)) { foreach ($assignMents as $_key => $_value) { $assignMentSelectArray[] = $_key; } } //所有角色{} $allRolesArray = $model->getAllRoles2SelectArray(); //用户信息 $user = User::findOne($user_id); return $this->render('assign_ment_edit', ['model' => $model, 'user' => $user, 'assignMentSelectArray' => $assignMentSelectArray, 'allRolesArray' => $allRolesArray]); } else { if (\Yii::$app->request->isPost) { $rs = $model->assign_user_create(\Yii::$app->request->post()); if ($rs) { jump_success(t_arr('app', ['update', 'success'], '', '!')); } else { jump_error(t_arr('app', ['update', 'fail'], '', '!')); } } } }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(self::EXCEPTION_MESS); } }