本文整理汇总了PHP中Space::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Space::save方法的具体用法?PHP Space::save怎么用?PHP Space::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Space
的用法示例。
在下文中一共展示了Space::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: actionAdmin
/**
* Setup Administrative User
*
* This should be the last step, before the user is created also the
* application secret will created.
*/
public function actionAdmin()
{
Yii::import('installer.forms.*');
$userModel = new User('register');
$userPasswordModel = new UserPassword('newPassword');
$profileModel = $userModel->profile;
$profileModel->scenario = 'register';
// Build Form Definition
$definition = array();
$definition['elements'] = array();
// Add User Form
$definition['elements']['User'] = array('type' => 'form', 'elements' => array('username' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 25), 'email' => array('type' => 'text', 'class' => 'form-control', 'maxlength' => 100)));
// Add User Password Form
$definition['elements']['UserPassword'] = array('type' => 'form', 'elements' => array('newPassword' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255), 'newPasswordConfirm' => array('type' => 'password', 'class' => 'form-control', 'maxlength' => 255)));
// Add Profile Form
$definition['elements']['Profile'] = array_merge(array('type' => 'form'), $profileModel->getFormDefinition());
// Get Form Definition
$definition['buttons'] = array('save' => array('type' => 'submit', 'class' => 'btn btn-primary', 'label' => Yii::t('InstallerModule.base', 'Create Admin Account')));
$form = new HForm($definition);
$form['User']->model = $userModel;
$form['User']->model->group_id = 1;
$form['UserPassword']->model = $userPasswordModel;
$form['Profile']->model = $profileModel;
if (isset($_POST['Profile'])) {
$_POST['Profile'] = Yii::app()->input->stripClean($_POST['Profile']);
}
if (isset($_GET['Profile'])) {
$_GET['Profile'] = Yii::app()->input->stripClean($_GET['Profile']);
}
if ($form->submitted('save') && $form->validate()) {
$this->forcePostRequest();
if (HSetting::Get('secret') == "") {
HSetting::Set('secret', UUID::v4());
}
$form['User']->model->status = User::STATUS_ENABLED;
$form['User']->model->super_admin = true;
$form['User']->model->language = '';
$form['User']->model->last_activity_email = new CDbExpression('NOW()');
$form['User']->model->save();
$form['Profile']->model->user_id = $form['User']->model->id;
$form['Profile']->model->title = "System Administration";
$form['Profile']->model->save();
// Save User Password
$form['UserPassword']->model->user_id = $form['User']->model->id;
$form['UserPassword']->model->setPassword($form['UserPassword']->model->newPassword);
$form['UserPassword']->model->save();
$userId = $form['User']->model->id;
// Switch Identity
Yii::import('application.modules_core.user.components.*');
$newIdentity = new UserIdentity($form['User']->model->username, '');
$newIdentity->fakeAuthenticate();
Yii::app()->user->login($newIdentity);
// Create Welcome Space
$space = new Space();
$space->name = 'Welcome Space';
$space->description = 'Your first sample space to discover the platform.';
$space->join_policy = Space::JOIN_POLICY_FREE;
$space->visibility = Space::VISIBILITY_ALL;
$space->created_by = $userId;
$space->auto_add_new_members = 1;
$space->save();
$profileImage = new ProfileImage($space->guid);
$profileImage->setNew($this->getModule()->getPath() . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR . 'welcome_space.jpg');
// Add Some Post to the Space
$post = new Post();
$post->message = "Yay! I've just installed HumHub :-)";
$post->content->container = $space;
$post->content->visibility = Content::VISIBILITY_PUBLIC;
$post->save();
$this->redirect($this->createUrl('finished'));
}
$this->render('admin', array('form' => $form));
}