本文整理汇总了PHP中app\modules\user\models\User::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getErrors方法的具体用法?PHP User::getErrors怎么用?PHP User::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::getErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$profile = new Profile();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->role = 'user';
$user->status = 1;
$profile->firstname = $this->firstname;
$profile->lastname = $this->lastname;
$profile->avatar = $this->avatar;
// $profile->gender = 0;
$transaction = Yii::$app->db->beginTransaction();
if ($user->save()) {
$profile->user_id = $user->getId();
if ($profile->save()) {
$transaction->commit();
return $user;
}
} else {
$transaction->rollback();
print_r($user->getErrors());
return false;
}
}
return null;
}
示例2: actionCreate
public function actionCreate()
{
$user = new User(['scenario' => 'admin-create']);
$profile = new Profile();
$statusArray = User::getStatusArray();
$roleArray = User::getRoleArray();
if ($user->load(Yii::$app->request->post())) {
if ($user->validate()) {
$transaction = Yii::$app->db->beginTransaction();
if ($user->save(false)) {
$profile->user_id = $user->getId();
if ($profile->save(false)) {
$transaction->commit();
return $this->redirect(['index']);
} else {
$transaction->rollback();
print_r($user->getErrors());
return false;
}
} else {
Yii::$app->session->setFlash('danger', 'Ошибка');
return $this->refresh();
}
}
}
// $transaction = Yii::$app->db->beginTransaction();
// if ($user->save())
// {
// $profile->user_id = $user->getId();
// if($profile->save())
// {
// $transaction->commit();
// return $user;
// }
// }
// else
// {
// $transaction->rollback();
// print_r($user->getErrors());
// return false;
// }
return $this->render('create', ['model' => $user, 'statusArray' => $statusArray, 'roleArray' => $roleArray]);
}