本文整理汇总了PHP中Space::addMember方法的典型用法代码示例。如果您正苦于以下问题:PHP Space::addMember方法的具体用法?PHP Space::addMember怎么用?PHP Space::addMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Space
的用法示例。
在下文中一共展示了Space::addMember方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
/**
* Registers a user
* @param array data
*/
private function registerUser($data)
{
$userModel = new User('register');
$userPasswordModel = new UserPassword();
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
// User: Set values
$userModel->username = $data['username'];
$userModel->email = $data['email'];
$userModel->group_id = $data['group_id'];
$userModel->status = User::STATUS_ENABLED;
// Profile: Set values
$profileModel->firstname = $data['firstname'];
$profileModel->lastname = $data['lastname'];
// Password: Set values
$userPasswordModel->setPassword($data['password']);
if ($userModel->save()) {
// Save user profile
$profileModel->user_id = $userModel->id;
$profileModel->save();
// Save user password
$userPasswordModel->user_id = $userModel->id;
$userPasswordModel->save();
// Join space / create then join space
foreach ($data['space_names'] as $key => $space_name) {
// Find space by name attribute
$space = Space::model()->findByAttributes(array('name' => $space_name));
// Create the space if not found
if ($space == null) {
$space = new Space();
$space->name = $space_name;
$space->save();
}
// Add member into space
$space->addMember($userModel->id);
}
return true;
} else {
Yii::app()->user->setFlash('error', CHtml::errorSummary($userModel));
return false;
}
}