本文整理汇总了PHP中app\models\User::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getId方法的具体用法?PHP User::getId怎么用?PHP User::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::getId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetIdMethods
public function testSetGetIdMethods()
{
$expected = 10;
$user = new User();
$user->setId($expected);
$this->assertEquals($expected, $user->getId());
}
示例2: userCreateOrUpdate
public function userCreateOrUpdate(User $user)
{
if (false == env('INTERCOM_ENABLED')) {
return false;
}
$user_data = ['user_id' => $user->getId(), 'email' => $user->email, 'last_request_at' => time(), 'custom_attributes' => ['username' => $user->username, 'first_name' => $user->first_name, 'last_name' => $user->last_name]];
$this->intercom->updateUser($user_data, true);
}
示例3: userCreateOrUpdate
protected function userCreateOrUpdate(User $user, $type)
{
if (false == env('MIXPANEL_ENABLED')) {
return false;
}
$this->mixpanel->setIdentity($user->getId());
$this->mixpanel->setIp($this->getIp());
$this->mixpanel->addTrackEvent($type, ['created_at' => time(), 'username' => $user->username, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'email' => $user->email]);
$this->mixpanel->addUserEvent('set', $type, ['$email' => $user->email, '$username' => $user->username, '$first_name' => $user->first_name, '$last_name' => $user->last_name]);
}
示例4: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->name = $this->name;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->save(false);
Yii::$app->authManager->assign(Yii::$app->authManager->getRole('user'), $user->getId());
return $user;
}
return null;
}
示例5: signup
/**
* Signs up the user.
* If scenario is set to "rna" (registration needs activation), this means
* that user need to activate his account using email confirmation method.
*
* @return User|null The saved model or null if saving fails.
*/
public function signup()
{
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->status = $this->status;
// if scenario is "rna" we will generate account activation token
if ($this->scenario === 'rna') {
$user->generateAccountActivationToken();
}
// if user is saved and role is assigned return user object
return $user->save() && RbacHelper::assignRole($user->getId()) ? $user : null;
}
示例6: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$user = new User(['scenario' => 'create']);
$role = new Role();
if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
$user->setPassword($user->password);
$user->generateAuthKey();
if ($user->save()) {
$role->user_id = $user->getId();
$role->save();
}
return $this->redirect('index');
} else {
return $this->render('create', ['user' => $user, 'role' => $role]);
}
}
示例7: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$user = new User(['scenario' => 'create']);
$role = new Role();
if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
$user->setPassword($user->password);
$user->generateAuthKey();
if ($user->save()) {
$role->user_id = $user->getId();
$role->save();
}
Yii::$app->session->setFlash('success', implode(' ', [ucfirst($user->username), ' successfully created!']));
return $this->redirect('index');
} else {
return $this->render('create', ['user' => $user, 'role' => $role]);
}
}
示例8: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('author');
$auth->assign($authorRole, $user->getId());
return $user;
}
}
return null;
}
示例9: reg
public function reg()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->status = $this->status;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($this->scenario === 'emailActivation') {
$user->generateSecretKey();
}
$user->save();
$auth = Yii::$app->authManager;
$simpleUser = $auth->getRole('simpleUser');
$auth->assign($simpleUser, $user->getId());
return $user;
}
}
示例10: reg
public function reg()
{
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->create_at = time();
if ($this->scenario === 'emailActivation') {
$user->generateSecretKey();
}
if ($user->save()) {
$userRole = Yii::$app->authManager->getRole('pay');
Yii::$app->authManager->assign($userRole, $user->getId());
return $user;
} else {
return null;
}
}
示例11: findByUser
/**
* Finds a throttler by the given Model.
*
* @param \App\Models\User $user
* @param string $ipAddress
*
* @return \App\Models\Throttle
*/
public function findByUser($user, $ipAddress = null)
{
$model = $this->model;
$query = $model->query()->where('user_id', '=', $userId = $user->getId());
if ($ipAddress) {
$query->where(function ($query) use($ipAddress) {
$query->where('ip_address', '=', $ipAddress);
$query->orWhere('ip_address', '=', null);
});
}
if (!($throttle = $query->first())) {
$throttle = $this->model;
$throttle->user_id = $userId;
if ($ipAddress) {
$throttle->ip_address = $ipAddress;
}
$throttle->save();
}
return $throttle;
}
示例12: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->status = User::STATUS_WAIT;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole('author');
$auth->assign($role, $user->getId());
Yii::$app->session->setFlash('success', 'bilo vislanno pismo dlya pottverjdeniya regi');
Yii::$app->mailer->compose(['html' => 'emailConfirm-html', 'text' => 'emailConfirm-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Account confirmation for ' . \Yii::$app->name)->send();
return $user;
}
}
return null;
}
示例13: registrations
public function registrations($link)
{
$data = time();
$user = new User();
$user->username = $this->username;
$user->password = '';
$user->generateAuthKey();
$user->u_snp = $this->name;
$user->u_company = $this->company;
$user->u_status = 0;
$user->u_activation_link = $link;
$user->u_time_link = $data;
$user->date_post = $data;
$user->update_post = $data;
$check = $user->save() ? $user : null;
// нужно добавить следующие три строки:
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->getId());
return $check;
// сохраняем нового пользователя, если все ок то тру, елсе фолс
}
示例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()
{
if (Yii::$app->user->can('user')) {
$model = new User();
$model->generateAuthKey();
$model->create_at = time();
$roles = ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description');
$user_permit = array_keys(Yii::$app->authManager->getRolesByUser($model->id));
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->authManager->revokeAll($model->getId());
if (Yii::$app->request->post('role')) {
foreach (Yii::$app->request->post('role') as $role) {
$new_role = Yii::$app->authManager->getRole($role);
Yii::$app->authManager->assign($new_role, $model->getId());
}
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'roles' => $roles, 'user_permit' => $user_permit]);
}
} else {
Yii::$app->session->setFlash('error', 'Нет доступа!');
$this->redirect('/');
}
}
示例15: getUserData
/**
* @param \app\models\User $user
* @return array
* [
* 'id' => идентификатор пользователя
* 'name' => Имя и фамилия
* 'avatar' => '/' относительный путь к аватару
* ]
*/
public function getUserData($user)
{
return ['id' => $user->getId(), 'name' => $user->getField('name_first') . ' ' . $user->getField('name_last'), 'avatar' => $user->getAvatar()];
}