本文整理汇总了PHP中backend\models\User::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findOne方法的具体用法?PHP User::findOne怎么用?PHP User::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backend\models\User
的用法示例。
在下文中一共展示了User::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionEdituser
public function actionEdituser()
{
$req = Yii::$app->request;
//创建一个请求对象
$form = new UserForm();
$form->setScenario('update');
$id = trim($req->get('id'));
if (!is_numeric($id) || $id == 0) {
$this->redirect(Variable::$userMange_url);
return;
}
//修改
if ($form->load($req->post()) && $form->validate()) {
$isSuccess = (new User())->updateCusetomer($id, $form->realName, $form->nickName, $form->password, $form->email, $form->mobile, $form->userType, $form->userStatus, $form->frozenReason, $form->comeFrom);
if ($isSuccess) {
$form->addError('', '资料更新成功');
} else {
$form->addError('', '资料更新失败');
}
}
$userModel = User::findOne($id);
$form->realName = $userModel->realName;
$form->nickName = $userModel->nickName;
$form->password = $userModel->password;
$form->email = $userModel->email;
$form->mobile = $userModel->mobile;
$form->userType = $userModel->userType;
$form->userStatus = $userModel->userStatus;
$form->frozenReason = $userModel->frozenReason;
$form->comeFrom = $userModel->comeFrom;
return $this->render(Variable::$editUser_view, ['model' => $form, 'userModel' => $userModel]);
}
示例2: actionPassword
public function actionPassword()
{
$model = User::findOne(Yii::$app->user->id);
$data = Yii::$app->request->post('User');
if (count($data)) {
if (isset($data['password'])) {
if ($model->validateName($data['username'])) {
if ($model->validatePassword($data['password_old']) && $model->validateName($data['username_old'])) {
$model->setAttributes($data);
$model->setPassword($model->password);
if ($model->save()) {
Yii::$app->session->setFlash('success', '密码修改成功');
} else {
Yii::$app->session->setFlash('danger', '密码修改失败');
}
} else {
Yii::$app->session->setFlash('danger', '原密码有误, 请输入正确的原密码');
}
} else {
Yii::$app->session->setFlash('danger', '用户名已存在请重试');
}
}
}
$result['model'] = $model;
return $this->render('password', $result);
}
示例3: actionSave
public function actionSave()
{
$this->_setJSONFormat(Yii::$app);
$request = Yii::$app->request;
$data = $request->post();
$code = '1';
if (!empty($data['_id'])) {
$product = Product::findOne($data['_id']['$id']);
$data['updatedAt'] = new \MongoDate();
$code = '2';
}
if (empty($product)) {
$product = new Product();
$accessToken = Token::getToken();
$user = User::findOne(['_id' => $accessToken->userId]);
$data['accountId'] = $this->getAccountId();
$data['creator'] = $user->name;
$data['createdAt'] = new \MongoDate();
$data['isDeleted'] = false;
}
if (!empty($product->accountId)) {
unset($data['accountId']);
}
$product->attributes = $data;
$product->save();
return ['code' => $code];
}
示例4: cekOldpassword
public function cekOldpassword($attribute)
{
$user = User::findOne(['id' => $this->id]);
if ($user->password != sha1($this->salt . $this->oldpass)) {
$this->addError($attribute, "Password yang Anda masukkan tidak sama dengan password saat ini");
}
}
示例5: findModel
/**
* 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.');
}
}
示例6: actionUserList
public function actionUserList($id = 0)
{
if ($id) {
return User::findOne($id)->username;
} else {
return $this->_list(new User(), 'user-list');
}
}
示例7: getUser
/**
* 获取用户对象
*/
public function getUser()
{
if ($this->getIsNewRecord()) {
return [];
}
$data = User::findOne($this->getAttribute('uid'));
return $data;
}
示例8: getParent
public function getParent($id)
{
$usr = User::findOne(['id' => $id]);
$cust = Customers::findOne(['customer_name' => $usr->fullname]);
//$usr = User::findOne(['id' => $cust->user_id]);
//var_dump($cust);
//die;
return $cust->typeprices_id;
}
示例9: findBusqueda
public function findBusqueda()
{
$data = $this->find();
$resultado = [];
foreach ($data as $ruta) {
$resultado[$ruta->id] = ['id' => $ruta->id, 'dia' => $ruta->dia, 'esActivo' => $ruta->esActivo, 'user' => User::findOne($ruta->id_usuario)->username];
}
return $resultado;
}
示例10: saveImportedCookbooks
public static function saveImportedCookbooks($datas, $accountId)
{
$results = [];
$accessToken = Token::getToken();
$userId = $accessToken->userId;
$user = User::findOne(['_id' => $userId]);
for ($i = 0; $i < sizeof($datas); $i++) {
$results[] = self::_saveSingleCookbook($datas[$i], $user, $accountId);
}
return $results;
}
示例11: actionView
public function actionView($id)
{
$model = $this->findModel($id);
$comerciosOrdenados = $model->getComerciosOrdenados();
$usuario = User::findOne($model->id_usuario);
$comercios = [];
$datosGrillaPasos = [];
$datosGrillaPasos[0] = ['orden' => 0, 'tipo' => Yii::t('core', 'User'), 'nombre' => $usuario->username, 'direccion' => $usuario->direccion, 'id_ruta_diaria' => $model->id, "id_comercio" => ''];
$i = 0;
foreach ($comerciosOrdenados as $comercio) {
$datosGrillaPasos[$i + 1] = ['orden' => $i + 1, 'tipo' => Yii::t('core', 'Store'), 'nombre' => $comercio->nombre, 'direccion' => $comercio->direccion, 'id_ruta_diaria' => $model->id, "id_comercio" => $comercio->id];
$i++;
}
$requestRuta = json_encode(sysconfigs::getRutaRequestParaMostrar($usuario, $comerciosOrdenados));
return $this->render('view', ['model' => $this->findModel($id), 'requestRuta' => $requestRuta, 'datosGrillaPasos' => $datosGrillaPasos]);
}
示例12: actionCreate
/**
* Creates a new Manager model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Manager();
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$user_id = Yii::$app->request->post('user_id');
$userModel = User::findOne($user_id);
if ($userModel) {
$model->created_at = time();
$model->updated_at = time();
$model->user_id = $userModel->id;
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
return $this->render('create', ['model' => $model]);
}
示例13: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = RutaDiaria::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$user = User::findOne(['id' => $this->id_usuario]);
$query->andFilterWhere(['id' => $this->id, 'fecha' => $this->fecha]);
if ($this->id_usuario != null) {
$query->andFilterWhere(['id_usuario' => $user != null ? $user->id : 0]);
}
return $dataProvider;
}
示例14: actionSave
public function actionSave()
{
$accountId = $this->getAccountId();
$adminId = $this->getParams("id");
$admin = User::findOne($adminId);
if ($admin == null) {
return ['code' => 1209, 'msg' => 'not login'];
}
$name = $this->getParams('name', '');
if ($name == '') {
return ['code' => 1202, 'msg' => 'Name is required.'];
}
$category = $this->getParams('category', '');
if ($category == '') {
return ['code' => 1202, 'msg' => 'Category is required.'];
}
$radio = $this->getParams('radio', true);
$cookingtypeId = $this->getParams('cookingtypeId', '');
$cookingType = null;
if ($cookingtypeId != '') {
$cookingType = CookingType::findOne($cookingtypeId);
if ($cookingType == null) {
return ['code' => 1204, 'msg' => 'cooking type not found.'];
} else {
$cookingTypes = CookingType::find()->where(['category' => $cookingType->name])->all();
for ($i = 0; $i < count($cookingTypes); $i++) {
$cookingTypes[$i]->category = $name;
$cookingTypes[$i]->save();
}
}
} else {
$cookingType = new CookingType();
}
$cookingType->name = $name;
$cookingType->category = $category;
$cookingType->operator = $admin['name'];
$cookingType->radio = $radio . '';
$cookingType->accountId = $accountId;
$cookingType->save();
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ['code' => 200, 'msg' => 'save success'];
}
示例15: actionSave
public function actionSave()
{
$this->delete();
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$request = Yii::$app->request;
$adminId = $request->post("id");
$admin = User::findOne($adminId);
if ($admin == null) {
return ['code' => 1209, 'msg' => 'not login'];
}
$accountId = $this->getAccountId();
$startDate = MongodbUtil::msTimetamp2MongoDate($request->post("startDate", ''));
$endDate = MongodbUtil::msTimetamp2MongoDate($request->post("endDate", ''));
$tags = $request->post("tags", '');
$startDateOrder = MongodbUtil::msTimetamp2MongoDate($request->post("startDateOrder", ''));
$endDateOrder = MongodbUtil::msTimetamp2MongoDate($request->post("endDateOrder", ''));
$tagsOrder = $request->post("tagsOrder");
$WestPromotionActivity = new WestPromotionActivity();
$WestPromotionActivity->accountId = $accountId;
$WestPromotionActivity->name = "registrationSetting";
$WestPromotionActivity->startDate = $startDate;
$WestPromotionActivity->endDate = $endDate;
$WestPromotionActivity->tags = $tags;
$result = $WestPromotionActivity->save();
if ($result <= 0) {
return ['msg' => 'failed', 'code' => '500'];
}
$WestPromotionActivity = new WestPromotionActivity();
$WestPromotionActivity->accountId = $accountId;
$WestPromotionActivity->name = "orderSetting";
$WestPromotionActivity->startDate = $startDateOrder;
$WestPromotionActivity->endDate = $endDateOrder;
$WestPromotionActivity->tags = $tagsOrder;
$result = $WestPromotionActivity->save();
if ($result > 0) {
return ['msg' => 'success', 'code' => '200'];
} else {
return ['msg' => 'failed', 'code' => '500'];
}
}