本文整理汇总了PHP中common\models\User::load方法的典型用法代码示例。如果您正苦于以下问题:PHP User::load方法的具体用法?PHP User::load怎么用?PHP User::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new User model.
* For ajax request will return json object
* and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$request = Yii::$app->request;
$model = new User();
if ($request->isAjax) {
/*
* Process for ajax request
*/
Yii::$app->response->format = Response::FORMAT_JSON;
if ($request->isGet) {
return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
} else {
if ($model->load($request->post()) && $model->save()) {
return ['code' => '200', 'message' => 'Create User success'];
} else {
return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
}
}
} else {
/*
* Process for non-ajax request
*/
if ($model->load($request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
}
示例2: actionCreate
/**
**创建一个新的用户.如果创建成功,浏览器会跳转到该用户的详情页面.
* @return mixed
*/
public function actionCreate()
{
$model = new User();
try {
if ($model->load($_POST) && $model->save()) {
return $this->redirect(Url::previous());
} elseif (!\Yii::$app->request->isPost) {
$model->load($_GET);
}
} catch (\Exception $e) {
$msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
$model->addError('_exception', $msg);
}
return $this->render('create', ['model' => $model]);
}
示例3: 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();
$model->scenario = 'create';
$userData = new UserData();
//$hotelMapping = new UserHotelMapping();
if ($model->load(Yii::$app->request->post()) && $userData->load(Yii::$app->request->post())) {
$validUser = $model->validate();
$validUserData = $userData->validate();
//$validHotelMapping = $hotelMapping->validate();
if ($validUser && $validUserData) {
// && $validHotelMapping
$model->setPassword($model->password);
$model->generateAuthKey();
if ($model->save()) {
$userData->user_id = $model->id;
//$hotelMapping->user_id = $model->id;
$userData->save(false);
//$hotelMapping->save(false);
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
return $this->render('create', ['model' => $model, 'userData' => $userData]);
}
示例4: actionCreate
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
$str = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('yyydmmdhis');
$potong = str_shuffle($str);
$random = substr($potong, 3, 12);
$model->setPassword($random);
$model->username = $_POST['User']['username'];
$model->role = $_POST['User']['role'];
$model->generateAuthKey();
$content = '
<center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
<h4 align="center">Badan Pengawas Tenaga Nuklir ' . date('Y') . '</h4>
<hr/>
<p>Yth ' . $model->username . ',<br/>
Dengan ini kami sampaikan akun telah terdaftar untuk masuk ke Sistem Aplikasi Perjalanan Dinas – BAPETEN, sebagai berikut:<br/>
Username : ' . $model->username . ' <br/>
Password :<b>' . $random . '</b><br/>
Mohon lakukan penggantian password Anda setelah melakukan login.\\n
Terima Kasih. <hr/>
<h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN ' . date('Y') . '</h5><br/>';
Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => $model->username])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
$model->save();
return $this->redirect(['index']);
} else {
var_dump($model->errors);
}
} else {
return $this->render('create', ['model' => $model]);
}
}
示例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($id)
{
$model = new User();
$model->loadDefaultValues();
$model->contact_id = $id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
//return $this->redirect(['contact/view', 'id' => $model->contact_id]);
return $this->redirect(Url::previous());
} elseif (!Yii::$app->request->isPost) {
$model->load(Yii::$app->request->get());
}
if (Yii::$app->request->isAjax) {
return $this->renderAjax('_form', ['model' => $model]);
}
return $this->render('create', ['model' => $model]);
}
示例6: actionCreateuser
public function actionCreateuser()
{
$userModel = User::findOne(['user_name' => yii::$app->request->post('user_name')]);
if ($userModel === null) {
$userModel = new User();
$userModel->load(yii::$app->request->post());
if ($userModel->save()) {
yii::$app->AjaxResponse->error = false;
yii::$app->AjaxResponse->message = ['User has been created'];
yii::$app->UserComponent->sendWelcomeEmail($userModel->first_name, $userModel->email);
} else {
yii::$app->AjaxResponse->message = array_values($userModel->getErrors());
}
} else {
// user exits but is not active
if ($userModel->status_id != Types::$status['active']['id']) {
$userModel->status_id = Types::$status['active']['id'];
$userModel->save();
yii::$app->AjaxResponse->error = false;
yii::$app->AjaxResponse->message = ['User reactivated'];
} else {
yii::$app->AjaxResponse->message = ['User already exists'];
}
}
yii::$app->AjaxResponse->sendContent();
}
示例7: 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->created_by = Yii::$app->user->identity->username;
$model->created_date = date('Y-m-d h:m:s');
$model->modified_by = Yii::$app->user->identity->username;
$model->modified_date = date('Y-m-d h:m:s');
$model->status = Status::STATUS_ACTIVE;
$model->generateUserActivationCode();
// $model->password_hash = md5($model->auth_key);
// $model->save();
$imageName = substr(md5(rand()), 0, 7);
if (UploadedFile::getInstance($model, 'file')) {
$model->file = UploadedFile::getInstance($model, 'file');
$model->image_path = 'uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension;
}
if ($model->save()) {
if ($model->image_path != null) {
$model->file->saveAs('uploads/user/' . $model->file->baseName . $imageName . '.' . $model->file->extension);
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
Yii::$app->session->setFlash('error', 'Insert Failed.');
return $this->render('create', ['model' => $model]);
}
Yii::$app->session->setFlash('success', 'Insert Success.');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例8: 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->username = $_POST['User']['username'];
$model->email = $_POST['User']['email'];
$model->password = $_POST['User']['password'];
$model->setPassword($_POST['User']['password']);
$model->generateAuthKey();
$model->fname = $_POST['User']['fname'];
$model->lname = $_POST['User']['lname'];
$model->groupid = $_POST['User']['groupid'];
$model->departmentid = $_POST['User']['departmentid'];
// $model->roleid = $_POST['User']['roleid'];
$model->roleid = 2;
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
print_r($model->getErrors());
}
// if ($id = $model->signup() ) {
// return $this->redirect(['view', 'id' => $id->id]);
// }
// if(is_null($model->signup())){
// // echo "Value is null";
// print_r($model->getErrors());
// }
}
return $this->render('create', ['model' => $model]);
}
示例9: 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();
$model->scenario = User::SCENARIO_CREATE;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (!($role = User::getAuthItem($model->role))) {
$model->addError('role', 'Role does not exist');
} else {
$transaction = $model->getDb()->beginTransaction();
try {
if ($model->save(false)) {
if (!$model->assignRole()) {
throw new Exception();
}
if (!Yii::$app->user->can(User::PERMISSION_CAN_CUD, $model)) {
throw new Exception();
}
$transaction->commit();
return $this->redirect('index');
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
}
return $this->render('create', ['model' => $model]);
}
示例10: actionReset
public function actionReset()
{
$this->layout = 'login';
$model = new User();
if ($model->load(Yii::$app->request->post())) {
if ($_POST['User']) {
$model->attributes = $_POST['User'];
$valid = $model->validate();
if ($valid) {
$model = User::find()->where(['email' => $_POST['User']['email']])->one();
$str = date('ymdhis') . 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' . date('d');
$potong = str_shuffle($str);
$random = substr($potong, 3, 12);
$model->setPassword($random);
$content = '
<center><img src="http://i.imgur.com/p5lHZXS.png"/></center><br/>
<h4 align="center">Badan Pengawas Tenaga Nuklir ' . date('Y') . '</h4>
<hr/>
<p>Yth ' . $model->username . ',<br/>
Dengan ini kami sampaikan password telah direset sebagai berikut:<br/>
Username : ' . $model->username . ' <br/>
Password :<b>' . $random . '</b><br/>
Mohon lakukan penggantian password Anda setelah melakukan login. <hr/>
<h5 align="center">Subbag Perjalanan Dinas Biro Umum BAPETEN ' . date('Y') . '</h5><br/>';
Yii::$app->mailer->compose("@common/mail/layouts/html", ["content" => $content])->setTo($_POST['User']['email'])->setFrom([$_POST['User']['email'] => 'Aplikasi Simpel Bapeten'])->setSubject('Ubah Kata Sandi')->setTextBody($random)->send();
$model->save();
return $this->redirect(['/site/login']);
}
}
}
return $this->render('reset', ['model' => $model]);
}
示例11: actionCreate
public function actionCreate()
{
$model = new User();
$model->scenario = 'create';
$users['User'] = Yii::$app->request->post();
if (Yii::$app->request->isPost && $model->load($users)) {
$model->password_hash = Yii::$app->request->post('password');
if (!empty($_FILES)) {
$upload = new UploadedFile();
$upload->name = $_FILES['image']['name'];
$upload->type = $_FILES['image']['type'];
$upload->tempName = $_FILES['image']['tmp_name'];
$upload->error = $_FILES['image']['error'];
$upload->size = $_FILES['image']['size'];
$model->image = $upload;
$filepath = Yii::getAlias('@uploadpath');
$model->image->saveAs($filepath . '/' . $model->image->baseName . '.' . $model->image->extension);
$model->setImage($model->image->name, FALSE);
}
if ($model->save()) {
return $model;
} else {
return $model->getErrors();
}
} else {
throw new ForbiddenHttpException('User is not saved successfully. Please try again with proper details.');
}
}
示例12: 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]);
}
}
示例13: 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()) {
Yii::$app->session->setFlash('success', 'Well done! successfully to save data! ');
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
/* @TODO: Remove this function later */
throw new \yii\web\ForbiddenHttpException('This method has been removed!');
$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]);
}
}
示例15: 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();
$model->scenario = 'create';
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model]);
}