本文整理匯總了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;
}
}