本文整理匯總了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()')]);
}