当前位置: 首页>>代码示例>>PHP>>正文


PHP User::getErrors方法代码示例

本文整理汇总了PHP中common\models\User::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getErrors方法的具体用法?PHP User::getErrors怎么用?PHP User::getErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\User的用法示例。


在下文中一共展示了User::getErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->username = $_POST['User']['username'];
         $model->email = $_POST['User']['email'];
         $model->password = $_POST['User']['password'];
         $model->setPassword($_POST['User']['password']);
         $model->generateAuthKey();
         $model->fname = $_POST['User']['fname'];
         $model->lname = $_POST['User']['lname'];
         $model->groupid = $_POST['User']['groupid'];
         $model->departmentid = $_POST['User']['departmentid'];
         //  $model->roleid = $_POST['User']['roleid'];
         $model->roleid = 2;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             print_r($model->getErrors());
         }
         //            if ($id = $model->signup() ) {
         //                return $this->redirect(['view', 'id' => $id->id]);
         //            }
         //            if(is_null($model->signup())){
         //              //  echo "Value is null";
         //                print_r($model->getErrors());
         //            }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:nirantarnoy,项目名称:paperless,代码行数:35,代码来源:UserController.php

示例2: actionCreate

 public function actionCreate()
 {
     $model = new User();
     $model->scenario = 'create';
     $users['User'] = Yii::$app->request->post();
     if (Yii::$app->request->isPost && $model->load($users)) {
         $model->password_hash = Yii::$app->request->post('password');
         if (!empty($_FILES)) {
             $upload = new UploadedFile();
             $upload->name = $_FILES['image']['name'];
             $upload->type = $_FILES['image']['type'];
             $upload->tempName = $_FILES['image']['tmp_name'];
             $upload->error = $_FILES['image']['error'];
             $upload->size = $_FILES['image']['size'];
             $model->image = $upload;
             $filepath = Yii::getAlias('@uploadpath');
             $model->image->saveAs($filepath . '/' . $model->image->baseName . '.' . $model->image->extension);
             $model->setImage($model->image->name, FALSE);
         }
         if ($model->save()) {
             return $model;
         } else {
             return $model->getErrors();
         }
     } else {
         throw new ForbiddenHttpException('User is not saved successfully. Please try again with proper details.');
     }
 }
开发者ID:sunil120,项目名称:yii2,代码行数:28,代码来源:UserController.php

示例3: actionUser

 /**
  * Create init user
  */
 public function actionUser()
 {
     echo "Create init user ...\n";
     // 提示当前操作
     $username = $this->prompt('User Name:');
     // 接收用户名
     $email = $this->prompt('Email:');
     // 接收Email
     $password = $this->prompt('Password:');
     // 接收密码
     $model = new User();
     // 创建一个新用户
     $model->username = $username;
     // 完成赋值
     $model->email = $email;
     $model->password = $password;
     if (!$model->save()) {
         foreach ($model->getErrors() as $error) {
             foreach ($error as $e) {
                 echo "{$e}\n";
             }
         }
         return 1;
         // 命令行返回1表示有异常
     }
     return 0;
     // 返回0表示一切OK
 }
开发者ID:packageman,项目名称:Yii2-advanced,代码行数:31,代码来源:InitController.php

示例4: actionCreateuser

 public function actionCreateuser()
 {
     $userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
     if ($userModel === null) {
         $userModel = new User();
         $userModel->load(yii::$app->request->post());
         if ($userModel->save()) {
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User has been created'];
             yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
         } else {
             yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
         }
     } else {
         // user exits but is not active
         if ($userModel->status_id != Types::$status['active']['id']) {
             $userModel->status_id = Types::$status['active']['id'];
             $userModel->save();
             yii::$app->AjaxResponse->error = false;
             yii::$app->AjaxResponse->message = ['User reactivated'];
         } else {
             yii::$app->AjaxResponse->message = ['User already exists'];
         }
     }
     yii::$app->AjaxResponse->sendContent();
 }
开发者ID:spiro-stathakis,项目名称:projects,代码行数:26,代码来源:AjaxController.php

示例5: actionCreateemployee

 public function actionCreateemployee()
 {
     $model = new User();
     $data = json_decode(file_get_contents("php://input"));
     $model->username = $data->username;
     $model->password = md5($data->password);
     $model->type = $data->type;
     $model->emp_id = strtotime(date("Y-m-d H:i:s"));
     $model->status = $data->status;
     $model->shop_id = Yii::$app->session->get('shopid');
     $model->created_at = date('Y-m-d');
     if ($model->save()) {
         echo "yes";
         exit;
         $response["status"] = 'success';
         $response["message"] = 'Employee added successfully.';
         $response["data"] = (int) $model->shop_id;
         http_response_code(200);
         header('Content-type: application/json');
         echo json_encode($response, JSON_NUMERIC_CHECK);
     } else {
         $response["status"] = 'error';
         $response["message"] = '';
         $response["error"] = $model->getErrors();
         header('Content-type: application/json');
         echo json_encode($response, JSON_NUMERIC_CHECK);
     }
 }
开发者ID:nahidlu,项目名称:easysale,代码行数:28,代码来源:EmployeeController.php

示例6: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->status = 0;
         if ($user->save()) {
             $notification = new Notification();
             $notification->title = 'user';
             $notification->message = 'new user, username:' . $user->username;
             $notification->params = \yii\helpers\Json::encode(['model' => 'User', 'id' => $user->id]);
             if ($notification->save()) {
                 $this->sendEmail($this->email);
             } else {
                 print_r($notification->getErrors());
                 exit(0);
             }
             return $user;
         } else {
             return $user->getErrors();
         }
     }
     return null;
 }
开发者ID:sintret,项目名称:yii2-advanced,代码行数:32,代码来源:SignupForm.php

示例7: showErrors

 /**
  * @param User $user
  */
 protected function showErrors($user)
 {
     $_errors = [];
     foreach ($user->getErrors() as $line) {
         $_errors = array_merge($_errors, $line);
     }
     $this->stderr("* " . implode("\n* ", $_errors) . "\n", Console::FG_RED);
 }
开发者ID:lav45,项目名称:yii2-translated-behavior-demo,代码行数:11,代码来源:UserController.php

示例8: signup

 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User(['scenario' => User::SCENARIO_REGISTER]);
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         } else {
             print_r($user->getErrors());
         }
     }
     return null;
 }
开发者ID:phisithos,项目名称:yii2-workshop-co-sapce,代码行数:21,代码来源:SignupForm.php

示例9: actionUser

 public function actionUser()
 {
     echo "Create init User .. \n";
     $username = $this->prompt('Input UserName: ');
     $email = $this->prompt("Input Email for {$username} :");
     $password = $this->prompt("Input password for {$username}:");
     $model = new User();
     $model->username = $username;
     $model->email = $email;
     $model->password = $password;
     if (!$model->save()) {
         foreach ($model->getErrors() as $errors) {
             foreach ($errors as $e) {
                 echo "{$e}\n";
             }
         }
         return 1;
     }
     return 0;
 }
开发者ID:xingcuntian,项目名称:advanced_study,代码行数:20,代码来源:InitController.php

示例10: actionInit

 public function actionInit()
 {
     $model = new User();
     $model->username = 'admin';
     $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG';
     $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC';
     $model->email = 'sintret@gmail.com';
     $model->phone = '6281575068530';
     $model->role = User::ROLE_ADMIN;
     $model->status = User::STATUS_ACTIVE;
     if ($model->save()) {
         echo "\r\n success insert user, with username:admin and password:123456 \r\n";
     } else {
         echo json_encode($model->getErrors());
     }
     $model = new Member();
     $model->username = 'admin';
     $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG';
     $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC';
     $model->email = 'sintret@gmail.com';
     $model->phone = '6281575068530';
     $model->role = Member::ROLE_ADMIN;
     $model->status = Member::STATUS_ACTIVE;
     if ($model->save()) {
         echo "\r\n success insert member, with username:admin and password:123456 \r\n";
     } else {
         echo json_encode($model->getErrors());
     }
     $setting = new Setting();
     $setting->emailAdmin = 'sintret@gmail.com';
     $setting->emailSupport = 'sintret@gmail.com';
     $setting->emailOrder = 'sintret@gmail.com';
     $setting->facebook = 'https://www.facebook.com/sintret';
     $setting->instagram = 'https://instagram.com/andyfitria/';
     $setting->google = 'https://google.com/sintret/';
     if ($setting->save()) {
         echo "\r\n success insert advanced settings... \r\n";
     } else {
         echo json_encode($setting->getErrors());
     }
 }
开发者ID:sintret,项目名称:yii2-advanced,代码行数:41,代码来源:InsertController.php

示例11: actionAdmin

 /**
  * Create init user
  */
 public function actionAdmin()
 {
     echo "Create A Admin Account ...\n";
     $username = $this->prompt('User Name:');
     $email = $this->prompt('Email:');
     $password = $this->prompt('Password:');
     $model = new User();
     $model->username = $username;
     $model->email = $email;
     $model->password = $password;
     $model->generateAuthKey();
     if (!$model->save()) {
         foreach ($model->getErrors() as $error) {
             foreach ($error as $e) {
                 echo "{$e}\n";
             }
         }
         return 1;
     }
     return 0;
 }
开发者ID:whystic,项目名称:yii2-whystic-blog,代码行数:24,代码来源:InitController.php

示例12: save

 public function save($runValidation = true, $attributeNames = null)
 {
     if ($this->validate()) {
         $user = new User();
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->pass_agreement = $this->pass_agreement;
         $user->generateAccessToken();
         if ($user->save()) {
             return $user;
         } else {
             if ($user->hasErrors()) {
                 foreach ($user->getErrors() as $error) {
                     $this->addError('email', $error[0]);
                 }
             } else {
                 throw new \Exception('create user failed, please contact the supporter');
             }
         }
     }
     return false;
 }
开发者ID:dawei101,项目名称:plants,代码行数:22,代码来源:SignupForm.php

示例13: actionUser

 public function actionUser()
 {
     echo "Create init user...\n";
     $username = $this->prompt('Input UserName: ');
     $email = $this->prompt("Input Email for {$username}: ");
     $password = $this->prompt("Input Password for {$username}: ");
     $realname = $this->prompt("Input RealName for {$username}: ");
     $head_image = $username . '.jpg';
     $model = new User();
     $model->username = $username;
     $model->email = $email;
     $model->password = $password;
     $model->realname = $realname;
     $model->head_image = $head_image;
     if (!$model->save()) {
         foreach ($model->getErrors() as $errors) {
             foreach ($errors as $e) {
                 echo "{$e}\n";
             }
         }
     } else {
         echo "You have created a user successfully!";
     }
 }
开发者ID:xujunfa,项目名称:jiajiao-yii2,代码行数:24,代码来源:InitController.php

示例14: checkout

 public function checkout($orderData = [])
 {
     $validator = new EmailValidator();
     $orderData = array_map('trim', $orderData);
     $orderData['email_validation'] = $validator->validate($orderData['email']) ? 1 : 0;
     $user = null;
     $userId = Yii::$app->session->get('userId');
     $user = User::find();
     if (!$userId) {
         $user = $user->where('email = :email', ['email' => $orderData['email']])->one();
     } else {
         $user = $user->where('id = :id', ['id' => $userId])->one();
     }
     if (!$user) {
         $user = new User();
         $user->email = $orderData['email'];
         $user->phone = $orderData['phone'];
         $user->name = $orderData['name'];
         $user->guid = Utils::createGuid();
         if (!$user->save()) {
             Yii::error(['info' => 'Проблема создания пользователя в БД', 'message' => $user->getErrors()], __LINE__);
         } else {
             $userId = $user->id;
             Yii::$app->session->set('userId', $userId);
         }
     } else {
         $userId = $user->id;
         Yii::$app->session->set('userId', $userId);
     }
     $this->device->linkUser($userId);
     $staticFolder = Yii::getAlias('@staticFolder');
     $result = ['result' => false];
     $cartGuid = Yii::$app->session->get('cartGuid');
     $order = CartOrder::find()->where('guid = :guid ', ['guid' => $cartGuid])->one();
     if ($order && $orderData) {
         $loader = new \Twig_Loader_Filesystem(Yii::getAlias('@common/mail'));
         $twig = new \Twig_Environment($loader, array('cache' => Yii::getAlias('@runtime/Twig/cache'), 'auto_reload' => TRUE));
         $items = $this->get($order->guid);
         $imgPrefix = Yii::getAlias('@imagePrefixOrder', false) ? Yii::getAlias('@imagePrefixOrder', false) : '200__';
         foreach ($items['items'] as &$item) {
             $item['productImage'] = str_replace('68_', $imgPrefix, $item['productImage']);
         }
         $relative_order_path = Yii::getAlias('@ordersFolder') . '/' . $cartGuid[0] . $cartGuid[1] . '/' . $cartGuid[2] . $cartGuid[3] . '/' . $cartGuid[4] . $cartGuid[5];
         $absolute_order_path = $staticFolder . '/' . $relative_order_path;
         $relative_order_file = $relative_order_path . '/' . $cartGuid . '.html';
         $absolute_order_file = $absolute_order_path . '/' . $cartGuid . '.html';
         if (!file_exists($absolute_order_path)) {
             mkdir($absolute_order_path, 0755, true);
         }
         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
             $ip = $_SERVER['HTTP_CLIENT_IP'];
         } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
             $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } else {
             $ip = $_SERVER['REMOTE_ADDR'];
         }
         $order->status = 1;
         $order->phone = $orderData['phone'];
         $order->email = $orderData['email'];
         $order->name = $orderData['name'];
         $order->delivery = $orderData['delivery'];
         $order->recipient_name = $orderData['recipient_name'];
         $order->recipient_passport = $orderData['recipient_passport'];
         $order->recipient_address = $orderData['recipient_address'];
         $order->comment = $orderData['comment'];
         $order->date = date('Y-m-d H:i:s', time());
         //            $order->date = new Expression('NOW()');
         //            $order->ip = new Expression('INET_ATON(:ip)',['ip' => $ip]);
         $order->ip = ip2long($ip);
         $order->order_file = $relative_order_file;
         $order->user_id = $userId;
         $order->email_validation = $orderData['email_validation'];
         if (!$order->save()) {
             Yii::error(['info' => 'Проблема сохранения заказа в БД', 'orderId' => $order->id, 'message' => $order->getErrors()], __LINE__);
             $result['result'] = 'error';
             return $result;
         }
         $htmlMessage = $twig->render('order/confirm.twig', array('order' => $order, 'orderDate' => date('d-m-Y', strtotime($order->date)), 'siteName' => Yii::getAlias('@protocol') . '://' . Yii::getAlias('@domain'), 'user' => $user, 'items' => $items['items']));
         $htmlMessageAdmin = $twig->render('order/confirmAdmin.twig', array('order' => $order, 'orderDate' => date('d-m-Y', strtotime($order->date)), 'siteName' => Yii::getAlias('@protocol') . '://' . Yii::getAlias('@domain'), 'user' => $user, 'items' => $items['items']));
         $content = $htmlMessage;
         $fp = fopen($absolute_order_file, 'wb');
         fwrite($fp, $content);
         fclose($fp);
         $send = $this->sendMail(['email' => $order->email, 'guid' => $user->guid, 'name' => $user->name], Yii::$app->params['replyToMail']['mail'], 'Ваш заказ принят', $htmlMessage, $order->guid);
         if (!$send['result']) {
             Yii::error(['info' => 'Проблема с отправкой уведомления о заказе клиенту', 'orderId' => $order->id, 'message' => $send['message']], __LINE__);
         }
         $send = $this->sendMail(['email' => Yii::$app->params['replyToMail']['mail'], 'guid' => null, 'name' => null], $order->email, 'Поступил заказ', $htmlMessageAdmin);
         if (!$send['result']) {
             Yii::error(['info' => 'Проблема с отправкой уведомления о заказе админу', 'orderId' => $order->id, 'message' => $send['message']], __LINE__);
         }
         // Заказ оформлен, очищаем сохранённую GUID заказа
         Yii::$app->session->remove('cartGuid');
         $result['email'] = $orderData['email'];
         $result['result'] = 'ok';
         $result['orderLink'] = '/' . $relative_order_file;
     }
     return $result;
 }
开发者ID:asakasinsky,项目名称:yii2-cart,代码行数:99,代码来源:Cart.php

示例15: actionCreateAdmin

    /**
     * 创建一个管理员用户
     * @author Fufeng Nie <niefufeng@gmail.com>
     */
    public function actionCreateAdmin()
    {
        echo '
         ┏┓   ┏┓+ +
        ┏┛┻━━━┛┻┓ + +
        ┃       ┃  
        ┃   ━   ┃ ++ + + +
        ████━████ ┃+
        ┃       ┃ +
        ┃   ┻   ┃
        ┃       ┃ + +
        ┗━┓   ┏━┛
          ┃   ┃           
          ┃   ┃ + + + +
          ┃   ┃    Code is far away from bug with the animal protecting       
          ┃   ┃ +     神兽保佑,代码无bug    ' . date('Y-m-d H:i:s') . '
          ┃   ┃
          ┃   ┃  +         
          ┃    ┗━━━┓ + +
          ┃        ┣┓
          ┃        ┏┛
          ┗┓┓┏━┳┓┏┛ + + + +
           ┃┫┫ ┃┫┫
           ┗┻┛ ┗┻┛+ + + +', "\n\n\n";
        do {
            $username = trim($this->prompt('请酝酿一个用户名,并在此输入:'));
            if ($username !== '') {
                break;
            }
            $this->stdout("\n错误:用户名不能为空\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        do {
            $email = trim($this->prompt("请给【{$username}】指定邮箱地址:"));
            if ($email !== '') {
                break;
            }
            $this->stdout("\n错误:邮箱地址不能为空\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        do {
            $password = trim($this->prompt("请给【{$username}】设定密码,密码不得少于6位:"));
            if ($password !== '') {
                break;
            }
            $this->stdout("\n错误:不是给你说了密码不能少于6位么?\n\n", Console::FG_RED, Console::UNDERLINE);
        } while (true);
        $userModel = new User();
        $userModel->username = $userModel->nickname = $username;
        $userModel->email = $email;
        $userModel->setPassword($password);
        $userModel->generateAuthKey();
        $userModel->status = User::STATUS_ACTIVE;
        echo "\n正在验证你输入的数据。。。\n\n";
        if (!$userModel->validate() || !$userModel->save()) {
            $this->stdout("发生了一些错误,你要有心理准备。。。\n\n", Console::FG_RED, Console::UNDERLINE);
            sleep(1);
            foreach ($userModel->getErrors() as $errors) {
                foreach ($errors as $error) {
                    echo "    {$error}\n";
                }
            }
            echo "\n";
            return 1;
        }
        echo "哎呀,我成了管理员啦,好紧张好激动啊!\n\n\n";
        return 0;
    }
开发者ID:luobenyu,项目名称:blog-1,代码行数:70,代码来源:InitController.php


注:本文中的common\models\User::getErrors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。