zhang1989

zhang1989

这家伙有点懒,还没写个性签名!

  • 财富值15
  • 威望值0
  • 总积分15

个人信息

  • 2015-08-12 已签到
    连续签到1天,获得了5个金钱
  • 提出了问题
    不使用GII的情况下,如何手动建立模块
  • 回复了 的回答

    我是新手,我都是这么写

                    $loginForm->attributes = array(
                        'username' => $_POST['username'],
                        'password' => $_POST['password'],
                        .....
                    );
    

    赋值完是不是要保存一下 $loginForm->save();
    var_dump($loginForm); 试试

    问题我已经解决了

  • 回复了 的回答

    你的 LoginForm 内容贴上来。

    问题我已经解决了

  • 回复了 的回答

    你的 LoginForm 内容贴上来。

    <?php

    /**

    • LoginForm class.
    • LoginForm is the data structure for keeping
    • user login form data. It is used by the 'login' action of 'SiteController'.
      */
      class LoginForm extends CFormModel
      {
      public $username;
      public $password;
      public $rememberMe;
      public $captcha;

      private $_identity;

      /**

      • Declares the validation rules.
      • The rules state that username and password are required,
      • and password needs to be authenticated.
        */
        public function rules()
        {
        return array(
          array('username , password ,captcha', 'safe'),
        // username and password are required
        array('username', 'required','message'=>'用户名不得为空'),
          array('password', 'required','message'=>'密码不得为空'),
        // rememberMe needs to be a boolean
        array('rememberMe', 'boolean'),
        // password needs to be authenticated
        array('password', 'authenticate'),
          //自定义验证码规则
          array('captcha','captcha','on'=>'login','message'=>'验证码不正确')//第1个captcha是表单名,第2个captcha是验证规则,message是错误提示信息
        

        );
        }
        /* public function scenarios()
        {
        return [

          'login'=>[ 'username', 'password','captcha']
        

        ];
        }/
        /
        *

      • Declares attribute labels.
        */
        public function attributeLabels()
        {
        return array(
        'rememberMe'=>'Remember me next time',
        

        );
        }

      /**

      • Authenticates the password.
      • This is the 'authenticate' validator as declared in rules().
        */
        public function authenticate($attribute,$params)
        {
        if(!$this->hasErrors())
        {
        $this->_identity=new UserIdentity($this->username,$this->password);
        if(!$this->_identity->authenticate())
        	$this->addError('password','密码不正确');
        

        }
        }

      /**

      • Logs in the user using the given username and password in the model.
      • @return boolean whether login is successful
        */
        public function login()
        {
        if($this->_identity===null)
        {
        $this->_identity=new UserIdentity($this->username,$this->password);
        $this->_identity->authenticate();
        

        }
        if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
        {

        $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
        Yii::app()->user->login($this->_identity,$duration);
        return true;
        

        }
        else

        return false;
        

        }
        }

实习生 等级规则
15/20
资料完整度
0/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

0

Ta的访客

0