hawkcraw 2013-04-08 16:26:16 3141次浏览 5条回复 0 0 0

我想做会员管理的模块 1.管理员角色可以新建、修改、删除用户。 2.一般会员角色只能更改自己的权限。

用户更新自己需要输入原始密码和新密码和确认密码。 管理员更新别的用户只需要新密码即可。

这是我的rules,在场景create,update下,没有问题, 但在edit场景(用于管理员更新他人)下,update场景的验证也都出来了,也就是说必须填重复密码和原始密码,各位仁兄帮帮忙,这个问题困扰我很久了!!谢谢

array('user_name', 'length', 'max'=>60),
array('user_pass', 'length', 'max'=>64),

array('user_pass', 'authenticate', 'on' => 'update'),
array('user_pass', 'required',  'on' => 'update'), 
array('new_pass,new_pass_repeat', 'required',  'on' => 'update,create'),
array('new_pass', 'length','min'=>5,  'on' => 'update,create,edit'),
array('new_pass_repeat', 'compare', 'compareAttribute'=>'new_pass',  'on' => 'update,create'),
  • 回复于 2013-04-08 17:19 举报

    谁来帮个

  • 回复于 2013-04-08 17:23 举报

    贴下你在edit下的代码

  • 回复于 2013-04-16 17:34 举报
    public function actionEdit($id){
            $user = Yii::app()->user;
    	$users = new Users('edit');
    	$model=$users->findByPk($id);
    	$roles = Role::model()->getRoleSelect();
    
    	// Uncomment the following line if AJAX validation is needed
    	// $this->performAjaxValidation($model);
    	if($user->id == $model->user_name)
    		$this->redirect(array('update','id'=>$model->user_id));
    
    	if($user->checkAccess('userUpdate')){
    		if(isset($_POST['Users']))
    		{
    				unset($_POST['Users']['user_name']);
    				$model->attributes=$_POST['Users'];
    				if($model->save())
    						$this->redirect(array('view','id'=>$model->user_id));
    		}
    
    		$this->render('edit',array(
    				'model'=>$model,
    				'roles'=>$roles,
    		));
    	}else{
    		$this->render('//site/error', array(
    			'message' => 'You are not authorized to perform this action.',
    			'code' => 403
    		));
    	}            
    
    }
    
  • 回复于 2013-04-16 17:35 举报

    这是我的EditAction,有问题吗??

  • 回复于 2013-04-17 10:45 举报

    额,都快十天了,还没解决。囧

    你为嘛要这么用呢。

    刚开始的几句:

    $model=Users::model()->findByPk($id);
    $model->setDbCriteria('edit') ;
    

    试试这样吧。

您需要登录后才可以回复。登录 | 立即注册