本文整理匯總了PHP中dektrium\user\models\User::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::validate方法的具體用法?PHP User::validate怎麽用?PHP User::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dektrium\user\models\User
的用法示例。
在下文中一共展示了User::validate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionCreate
/**
* Creates a new SocialServiceManager model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new SocialServiceManager();
if ($model->load(Yii::$app->request->post())) {
$person = new Person();
$person->name = $model->name;
$person->lastname = $model->last_name;
$person->phone = $model->phone;
$person->save(false);
$user = new User();
$user->username = $model->username;
$user->password = $model->password;
$user->email = $model->email;
$user->person_id = $person->id;
$user->scenario = 'register';
if ($user->validate(['username', 'password'])) {
$user->register();
$model->user_id = $user->id;
$model->save(false);
//assign the role to the user
$authManager = Yii::$app->getAuthManager();
$socialServiceMRole = $authManager->getRole('socialServiceManager');
$authManager->assign($socialServiceMRole, $user->id);
//set the success message
Yii::$app->getSession()->setFlash('success', 'Usuario creado con éxito');
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->addErrors($user->errors);
}
}
return $this->render('create', ['model' => $model]);
}