本文整理汇总了PHP中YumUser::syncRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP YumUser::syncRoles方法的具体用法?PHP YumUser::syncRoles怎么用?PHP YumUser::syncRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YumUser
的用法示例。
在下文中一共展示了YumUser::syncRoles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new User.
*/
public function actionCreate()
{
$user = new YumUser();
if (Yum::hasModule('profile')) {
$profile = new YumProfile();
}
$passwordform = new YumUserChangePassword();
// When opening a empty user creation mask, we most probably want to
// insert an _active_ user
if (!$user->status) {
$user->status = 1;
}
if (isset($_POST['YumUser'])) {
$user->attributes = $_POST['YumUser'];
if (isset($_POST['YumUserChangePassword'])) {
if ($_POST['YumUserChangePassword']['password'] == '') {
Yii::import('user.components.EPasswordGenerator');
$generatorOptions = Yum::module()->passwordGeneratorOptions;
$password = EPasswordGenerator::generate($generatorOptions['length'], $generatorOptions['capitals'], $generatorOptions['numerals'], $generatorOptions['symbols']);
$user->setPassword($password);
Yum::setFlash(Yum::t('The generated Password is {password}', array('{password}' => $password)));
} else {
$passwordform->attributes = $_POST['YumUserChangePassword'];
if ($passwordform->validate()) {
$user->setPassword($_POST['YumUserChangePassword']['password']);
}
}
}
$user->validate();
if (Yum::hasModule('profile') && isset($_POST['YumProfile'])) {
$profile->attributes = $_POST['YumProfile'];
}
if (!$user->hasErrors()) {
$user->activationKey = CPasswordHelper::hashPassword(microtime() . $user->password, Yum::module()->passwordHashCost);
if ($user->username == '' && isset($profile)) {
$user->username = $profile->email;
}
if (isset($profile)) {
$profile->validate();
}
if (!$user->hasErrors() && !$passwordform->hasErrors()) {
$user->save();
if (isset($_POST['YumUser']['roles'])) {
$user->syncRoles($_POST['YumUser']['roles']);
} else {
$user->syncRoles();
}
if (isset($profile)) {
$profile->user_id = $user->id;
$profile->save(array('user_id'), false);
}
$this->redirect(array('view', 'id' => $user->id));
}
}
}
$this->render('create', array('user' => $user, 'passwordform' => $passwordform, 'profile' => isset($profile) ? $profile : null));
}