本文整理汇总了PHP中app\modules\user\models\User::load方法的典型用法代码示例。如果您正苦于以下问题:PHP User::load方法的具体用法?PHP User::load怎么用?PHP User::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::load方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例2: actionCreate
/**
* Creates a new Person model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Person();
$modelUser = new User();
$modelAuthRule = new AuthRule();
$modelAuthItem = new AuthItem();
$authRule = AuthRule::find()->all();
$authItem = AuthItem::find()->all();
if (Yii::$app->request->isPost) {
// do transaction if fails it will not saved
$transaction = Yii::$app->db->beginTransaction();
try {
if ($modelUser->load(Yii::$app->request->post()) && $modelUser->validate()) {
$modelUser->generateAuthKey();
// first attempt save user record
if ($modelUser->save()) {
if ($model->load(Yii::$app->request->post())) {
$model->user_id = $modelUser->id;
// second attemp save person record
if ($model->validate() && $model->save()) {
if ($modelAuthItem->load(Yii::$app->request->post()) && $modelAuthItem->validate()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole($modelAuthItem->name);
if (!empty($role)) {
// thrid attemp assign role to user
$auth->assign($role, $modelUser->id);
$transaction->commit();
Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Karyawan Berhasil Disimpan'));
return $this->redirect(['index']);
} else {
throw new \Exception("AuthRole search data checkpoint fail to save");
}
} else {
throw new \Exception("AuthItem (Role) validation checkpoint fail to save");
}
} else {
throw new \Exception("Person save checkpoint fail to save");
}
} else {
throw new \Exception("Person loaded checkpoint fail to save");
}
} else {
throw new \Exception("User save checkpoint fail to save");
}
} else {
throw new \Exception("User validation checkpoint fail to save");
}
} catch (\Exception $e) {
$transaction->rollback();
Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Karyawan Gagal Disimpan'));
}
}
return $this->render('create', ['model' => $model, 'modelUser' => $modelUser, 'modelAuthRule' => $modelAuthRule, 'authRule' => $authRule, 'modelAuthItem' => $modelAuthItem, 'authItem' => $authItem]);
}
示例3: actionCreate
public function actionCreate()
{
$model = new User(['scenario' => 'admin-create']);
$statusArray = User::getStatusArray();
$roleArray = User::getRoleArray();
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model, 'statusArray' => $statusArray, 'roleArray' => $roleArray]);
}
示例4: Register
public function Register()
{
if ($this->validate()) {
$user = new User();
$userProps['User'] = $this->getAttributes();
$user->load($userProps);
$user->save();
Yii::$app->user->login($user, 60 * 60 * 24 * 365);
return true;
} else {
return false;
}
}
示例5: 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())) {
$security = new Security();
$model->password = $security->generatePasswordHash(md5($model->password));
$model->auth_key = $security->generateRandomString(64);
$model->created_date = time();
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例6: 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]);
}