當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::hasErrors方法代碼示例

本文整理匯總了PHP中dektrium\user\models\User::hasErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::hasErrors方法的具體用法?PHP User::hasErrors怎麽用?PHP User::hasErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dektrium\user\models\User的用法示例。


在下文中一共展示了User::hasErrors方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: safeUp

 public function safeUp()
 {
     $app = Yii::$app;
     $app->setModule('user', ['class' => 'dektrium\\user\\Module']);
     if (!isset($app->get('i18n')->translations['user*'])) {
         $app->get('i18n')->translations['user*'] = ['class' => \yii\i18n\PhpMessageSource::className(), 'basePath' => Yii::getAlias('@dektrium/user/migrations')];
     }
     $controller = Yii::$app->controller;
     $user = new User(['scenario' => 'register']);
     echo $controller->ansiFormat("\n\n ==> Create Admin User\n", \yii\helpers\Console::FG_CYAN);
     do {
         if ($user->hasErrors()) {
             $this->showErrors($user);
         }
         // get email
         $email = $controller->prompt($controller->ansiFormat("\tE-mail: ", \yii\helpers\Console::FG_BLUE));
         // get username
         $username = $controller->prompt($controller->ansiFormat("\tUsername: ", \yii\helpers\Console::FG_BLUE));
         // get password
         echo $controller->ansiFormat("\tPassword: ", \yii\helpers\Console::FG_BLUE);
         system('stty -echo');
         $password = trim(fgets(STDIN));
         system('stty echo');
         echo "\n";
         $affectedRows = Yii::$app->db->createCommand()->insert('{{%user}}', ['username' => (string) $username, 'email' => $email, 'password_hash' => Password::hash($password), 'confirmed_at' => new Expression('UNIX_TIMESTAMP()')])->execute();
     } while ($affectedRows < 1);
     do {
         // get realname
         $name = $controller->prompt($controller->ansiFormat("\tFull name: ", \yii\helpers\Console::FG_BLUE));
         echo "\n\n";
     } while (empty($name));
     $userPrimaryKey = User::findOne(['email' => $email])->primaryKey;
     $this->update('{{%profile}}', ['name' => $name], 'user_id=:user_id', [':user_id' => $userPrimaryKey]);
     $this->insert('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $userPrimaryKey, 'created_at' => new Expression('UNIX_TIMESTAMP()')]);
 }
開發者ID:hector-del-rio,項目名稱:yii2-attache,代碼行數:35,代碼來源:m150805_191756_yii2user_add_admin_user.php


注:本文中的dektrium\user\models\User::hasErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。