本文整理汇总了PHP中app\models\User::load方法的典型用法代码示例。如果您正苦于以下问题:PHP User::load方法的具体用法?PHP User::load怎么用?PHP User::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Anlegen eines Benutzers
*
* @return \yii\web\View
* @author KAS <kassel@weitkamper.de> 28.07.2015
*/
public function actionCreate()
{
Yii::$app->view->params['headline'] = 'Benutzer anlegen';
$model = new User();
//----------------------------------------------------------------------
$post = \Yii::$app->request->post();
if ($model->load($post)) {
$authArr = [];
foreach ($post['Auth'] as $authData) {
$authArr[] = new Auth($authData);
}
// Daten Validieren und Zuordnen -----------------------------------
if (Model::loadMultiple($authArr, $post) && Model::validateMultiple($authArr)) {
// aus den Auth Objekten machen wir arrays,
// damit wir das in die Mongo speichern können
$model->auth = array_map(function ($a) {
return $a->toArray();
}, $authArr);
// Speichern ---------------------------------------------------
$model->save();
// Benutzer benachrichtigen ------------------------------------
\Yii::$app->session->setFlash('success', 'Benutzer wurde erfolgreich angelegt!', TRUE);
// Neue Daten laden, da wir in den Models Veränderungen vornehmen
$model->refresh();
}
}
// Defaultwerte festlegen ----------------------------------------------
$model->created_at = new \MongoDate();
$model->updated_at = new \MongoDate();
$model->role = "Normal";
//----------------------------------------------------------------------
return $this->render('create', ['model' => $model]);
}
示例2: 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 ['title' => "Create new User", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
} else {
if ($model->load($request->post()) && $model->save()) {
return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new User", 'content' => '<span class="text-success">Create User success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
} else {
return ['title' => "Create new User", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
}
}
} 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]);
}
}
}
示例3: actionUser
public function actionUser()
{
//make a db con or go back
$db = new InstallConfig();
try {
$db->con();
} catch (\yii\db\Exception $e) {
return $this->render('config', array('model' => $db, "error" => "No DB"));
}
if (!User::find()->All() == null) {
return $this->redirect('?r=install/finish');
//Yii::$app->end();
}
//user
$model = new User();
$model->scenario = 'create';
$model->language = 'he_il';
$model->timezone = 'Asia/Jerusalem';
if ($model->load(Yii::$app->request->post())) {
//$model->save();
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\bootstrap\ActiveForm::validate($model);
}
if ($model->save()) {
$this->redirect('?r=install/finish');
}
}
return $this->render('user', array('model' => $model));
}
示例4: 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())) {
//Begin transaction
$transaction = Yii::$app->db->beginTransaction();
$imageName = $model->username;
$model->file = UploadedFile::getInstance($model, 'file');
$model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
$model->photo = 'uploads/' . $imageName . '.' . $model->file->extension;
try {
//save guest to database
if ($model->save()) {
$model->idUser;
$model->setPassword($model->password);
// $modelCustomer->re_password = $modelCustomer->password;
if ($model->save()) {
$transaction->commit();
if (Yii::$app->getUser()->login($model)) {
return $this->redirect(['view', 'id' => $model->idUser, 'username' => $model->username, 'email' => $model->email]);
}
} else {
return $this->render('create', ['model' => $model]);
}
} else {
return $this->render('create', ['model' => $model]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
} 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()
{
$modelUser = new User();
$modelProfile = new Profile();
$roles = AuthItem::find()->all();
$arrayRoles = ArrayHelper::map($roles, 'name', 'description');
$regions = Region::find()->all();
$arrayRegions = ArrayHelper::map($regions, 'id', 'name');
if ($modelUser->load(Yii::$app->request->post())) {
if ($modelUser->validate()) {
$modelUser->setPassword($modelUser->password_hash);
if ($modelUser->save(false)) {
$modelProfile->user_id = $modelUser->id;
$modelProfile->worker_name = $modelUser->worker_name;
$modelProfile->telephone = $modelUser->telephone;
$modelProfile->head_position = $modelUser->head_position;
$modelProfile->head_name = $modelUser->head_name;
$modelProfile->region_id = $modelUser->region;
if ($modelProfile->save(false)) {
$auth = Yii::$app->authManager;
$auth->revokeAll($modelUser->id);
$access = $auth->getRole($modelUser->access);
if ($auth->assign($access, $modelUser->id)) {
return $this->redirect(['view', 'id' => $modelUser->id]);
}
}
}
}
}
return $this->render('create', ['model' => $modelUser, 'arrayRoles' => $arrayRoles, 'arrayRegions' => $arrayRegions]);
}
示例6: actionRacer
public function actionRacer()
{
$user = new User();
$racer = new Racer();
$races = Race::findAll(['status' => 'PENDING']);
if ($user->load(Yii::$app->request->post()) && $racer->load(Yii::$app->request->post())) {
$user->type = 'RACER';
$user->status = 'ACTIVE';
$user->password = hash('sha256', $user->identity);
$user->creation_date = date('Y-m-d H:i:s');
if ($user->save()) {
$racer->place = strtoupper($racer->place);
$racer->user_id = $user->id;
$racer->creation_date = date('Y-m-d H:i:s');
if ($racer->save()) {
Yii::$app->session->setFlash('racerCreated');
return $this->redirect(['racer']);
} else {
Yii::$app->session->setFlash('errorRacer', array_values($racer->getFirstErrors())[0]);
}
} else {
Yii::$app->session->setFlash('errorRacer', array_values($user->getFirstErrors())[0]);
}
}
return $this->render('racer', ['user' => $user, 'racer' => $racer, 'races' => $races]);
}
示例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();
try {
if ($model->load($_POST)) {
$model->password = md5($model->password);
$image = UploadedFile::getInstance($model, 'photo_url');
if ($image != NULL) {
# store the source file name
$model->photo_url = $image->name;
$extension = end(explode(".", $image->name));
# generate a unique file name
$model->photo_url = Yii::$app->security->generateRandomString() . ".{$extension}";
# the path to save file
$path = Yii::getAlias("@app/web/uploads/") . $model->photo_url;
$image->saveAs($path);
} else {
$model->photo_url = "default.png";
}
$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]);
}
示例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()
{
if (Yii::$app->user->can('userCreate')) {
//The permission name
//The actions...
$model = new User();
$role = new AuthItem();
$model->scenario = 'create';
if ($model->load(Yii::$app->request->post())) {
$role->load(Yii::$app->request->post());
$model->accessToken = md5(rand(0, 1000));
$model->score = 0;
if ($model->save()) {
$auth = Yii::$app->authManager;
$newRole = $auth->getRole($role->name);
$auth->assign($newRole, $model->getId());
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model, 'role' => $role]);
}
} else {
if (Yii::$app->user->isGuest) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}
}
示例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->active = true;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->rol == 'Básico') {
$auth = Yii::$app->authManager;
$roles = $auth->getRole('Básico');
$auth->assign($roles, $model->id);
}
if ($model->rol == 'Operador') {
$auth = Yii::$app->authManager;
$roles = $auth->getRole('Operador');
$auth->assign($roles, $model->id);
}
if ($model->rol == 'Administrador') {
$auth = Yii::$app->authManager;
$roles = $auth->getRole('Administrador');
$auth->assign($roles, $model->id);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例10: actionSignup
public function actionSignup()
{
$post = Application::request()->post();
$warning = '';
if (sizeof($post) > 0) {
$model = new User();
$model->load($post);
$validation = $model->validate();
if ($validation) {
$user_id = $model->save();
if ($user_id) {
Application::Identity()->signin($user_id);
$this->redirect('/search');
} else {
$warning = 'Error adding row to DB';
}
} else {
$warning = 'Please enter correct fields values';
}
}
if (!Application::Identity()->check()) {
$this->render('signup.html', ['salt' => Helper::generateCode(15), 'warning' => $warning]);
} else {
$this->redirect('/search');
}
}
示例11: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$email = new Email();
$email->to_name = $model->name;
$email->to_email = $model->email;
$email->subject = "Your Tixty Purchase";
$message = <<<EOT
Hi {$model->name}!!
You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a>
Thanks,
Tixty
EOT;
$email->body = nl2br($message);
$email->save();
$email->send();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例12: actionRegister
public function actionRegister()
{
if (!Application::$app->getUser()->getIsGuest()) {
Application::$app->getSession()->setFlash('register-warning', 'You must be unauthorized');
return $this->redirect('site/index');
}
if (!empty($_POST) && (!isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['repeat_password']) || empty($_POST['repeat_password']))) {
Application::$app->getSession()->setFlash('register-danger', 'Please fill all fields.');
} elseif (!empty($_POST) && $_POST['password'] !== $_POST['repeat_password']) {
Application::$app->getSession()->setFlash('register-danger', 'Passwords not match.');
} elseif (!empty($_POST)) {
//check email
$model = User::findIdentityByEmail($_POST['email']);
if (!empty($model)) {
Application::$app->getSession()->setFlash('register-danger', 'User with email ' . HtmlPurifier::process($_POST['email']) . ' already registered.');
return $this->redirect('user/register');
}
$model = new User();
$model->load($_POST);
$model->insert();
Application::$app->getSession()->setFlash('register-success', 'User successfully created.');
return $this->redirect('user/login');
}
return $this->render('user/register');
}
示例13: actionCreate
/**
* Creates a new Student model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$student = new Student();
$user = new User();
$person = new Person();
if (Yii::$app->request->post()) {
$params = Yii::$app->request->post();
$person->load($params);
$user->load($params);
$user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
$student->load($params);
if ($person->validate() && $user->validate() && $student->validate()) {
$person->save(false);
$user->person_id = $person->id;
$user->register();
$student->user_id = $user->id;
$student->save();
Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
return $this->refresh();
} else {
Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
return $this->refresh();
}
} else {
return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
}
}
示例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()
{
$model = new User();
if ($model->load(Yii::$app->request->post())) {
$model->setPassword($model->password);
$model->username = $model->email;
if ($model->save()) {
$model->generateAuthKey();
if ($model->user_role == 'host') {
// the following three lines were added:
$auth = Yii::$app->authManager;
$hostRole = $auth->getRole('host');
$auth->assign($hostRole, $model->id);
// return $this->redirect(['hosts/index', 'id' => $model->id]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
} 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();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->addFlash('success', "Запись \"{$model->name}\" успешно добавлена.");
return $this->redirect(Url::previous() != Yii::$app->homeUrl ? Url::previous() : ['view', 'id' => $model->id]);
} else {
if (Yii::$app->request->referrer != Yii::$app->request->absoluteUrl) {
Url::remember(Yii::$app->request->referrer ? Yii::$app->request->referrer : null);
}
if (!Yii::$app->request->isPost) {
$model->load(Yii::$app->request->get());
}
return $this->render('create', ['model' => $model]);
}
}