本文整理汇总了PHP中UserForm::save方法的典型用法代码示例。如果您正苦于以下问题:PHP UserForm::save方法的具体用法?PHP UserForm::save怎么用?PHP UserForm::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserForm
的用法示例。
在下文中一共展示了UserForm::save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$model = new UserForm();
if (($post = $this->request->getPost('UserForm', false)) !== false) {
$model->attributes = $post;
if ($model->save()) {
$this->response(200, '更新用户成功');
} else {
$this->response(500, '更新用户失败');
}
$this->app->end();
} else {
if (($id = $this->request->getQuery('id', 0)) != false) {
if (($user = User::model()->findByPk($id)) != false) {
$model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => $user->state];
$auth = $this->app->getAuthManager();
$roles = $auth->getRoleByUserId($id);
$role = [];
foreach ($roles as $item) {
$role[] = $item->getId();
}
$groups = $auth->getGroupByUserId($id);
$group = [];
foreach ($groups as $item) {
$group[] = $item->getId();
}
$this->render('edit', ['model' => $model, 'role' => $role, 'group' => $group, 'roleList' => Role::model()->findAll(), 'groupList' => Group::model()->findAll()]);
$this->app->end();
}
}
}
$this->response(404, '参数错误');
}
示例2: actionAccount
public function actionAccount()
{
$model = new UserForm();
if (($post = $this->request->getPost('UserForm', false)) != false) {
$model->attributes = $post;
if ($model->save()) {
$this->user->logout();
$this->redirect($this->createUrl('index'));
}
}
$this->render('account', ['model' => $model, 'service' => Service::model()->findByPk($this->user->getId())]);
}
示例3: actionEdit
public function actionEdit()
{
$model = new UserForm();
if (($post = $this->request->getPost('UserForm', false)) !== false) {
$post['state'] = -1;
$model->attributes = $post;
if ($model->save()) {
$this->response(200, '更新用户成功');
} else {
$this->response(500, '更新用户失败');
}
} else {
if (($id = $this->request->getQuery('id', 0)) != false) {
if (($user = User::model()->findByPk($id)) != false) {
$model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => -1];
$this->render('edit', ['model' => $model]);
}
} else {
$this->response(404, '参数错误');
}
}
}
示例4: actionUpdate
public function actionUpdate()
{
$companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId'));
$id = Yii::app()->request->getParam('id');
Until::isUpdateValid(array($id), $companyId, $this);
//0,表示企业任何时候都在云端更新。
if (Yii::app()->user->role > User::ADMIN && Yii::app()->user->userId != $id) {
Yii::app()->user->setFlash('error', yii::t('app', '你没有权限修改'));
$this->redirect(array('user/index', 'companyId' => $companyId));
}
$model = new UserForm();
$model->find('lid=:id and dpid=:dpid and status=1', array(':id' => $id, ':dpid' => $companyId));
if (Yii::app()->request->isPostRequest) {
$model->attributes = Yii::app()->request->getPost('UserForm');
//$model->update_at=date('Y-m-d H:i:s',time());
//var_dump($model->attributes);exit;
if ($model->save()) {
Yii::app()->user->setFlash('success', yii::t('app', '修改成功'));
$this->redirect(array('user/index', 'companyId' => $companyId));
}
}
$this->render('update', array('model' => $model));
}
示例5: configure
$methods = array('widgetChoiceTableMethod1', 'widgetChoiceTableMethod2', 'widgetChoiceTableMethod3');
foreach ($methods as $method) {
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => $method));
$t->is($widget->getChoices(), array(1 => 1));
}
$widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => 'widgetChoiceTableMethod4'));
$t->is($widget->getChoices(), array());
$user = new User();
$user->Groups[]->name = 'User Group 1';
$user->Groups[]->name = 'User Group 2';
class UserGroupForm extends GroupForm
{
public function configure()
{
parent::configure();
$this->useFields(array('name'));
}
}
$userForm = new UserForm($user);
$userForm->embedRelation('Groups', 'UserGroupForm');
$data = array('username' => 'jonwage', 'password' => 'changeme', 'Groups' => array(0 => array('name' => 'New User Group 1 Name'), 1 => array('name' => 'New User Group 2 Name')));
$userForm->bind($data);
$t->is($userForm->isValid(), true);
if ($userForm->isValid()) {
$userForm->save();
}
$t->is($user->Groups[0]->name, 'New User Group 1 Name');
$t->is($user->Groups[1]->name, 'New User Group 2 Name');
$form = new DefaultValueTestForm();
$validatorSchema = $form->getValidatorSchema();
$t->is($validatorSchema['name']->getOption('required'), false);
示例6: actionCreateAdmin
/**
* This action enables us to create an admin user for CiiMS
*/
public function actionCreateAdmin()
{
$this->stage = Yii::app()->session['stage'] = 6;
$model = new UserForm();
if (Cii::get($_POST, 'UserForm') != NULL) {
$model->attributes = Cii::get($_POST, 'UserForm', array());
if ($model->save()) {
$this->redirect($this->createUrl('/admin'));
}
$errors = $model->getErrors();
$firstError = array_values($errors);
Yii::app()->user->setFlash('error', Yii::t('Install.main', '{{warning}} {{error}}', array('{{warning}}' => CHtml::tag('strong', array(), Yii::t('Install.main', 'Warning!')), '{{error}}' => $firstError[0][0])));
}
$this->render('createadmin', array('model' => $model));
}