2015-06-01 23:57:39 6267次浏览 2条回答 0 悬赏 0 金钱

$loginForm=new LoginForm;//loginForm模型是Yii提供的登陆验证模型
if(isset($_POST['LoginForm'])){

$loginForm->attributes=$_POST['LoginFrom'];//将表单数据提交给一个变量集合
var_dump($loginForm->attributes);
exit;

if($loginForm->validate()){//开始验证提交的变量
    echo '111111';
}

}

已经解决了,赋值的时候变量写错了,谢谢大家关注

  • 回答于 2015-06-02 11:31 举报

    你的 LoginForm 内容贴上来。

    2 条回复
    回复于 2015-06-02 22:39 回复

    <?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;
        

        }
        }

    回复于 2015-06-03 08:19 回复

    问题我已经解决了

  • 回答于 2015-06-02 14:43 举报

    我是新手,我都是这么写

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

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

    1 条回复
    回复于 2015-06-03 08:19 回复

    问题我已经解决了

您需要登录后才可以回答。登录 | 立即注册
zhang1989
实习生

zhang1989

注册时间:2015-06-01
最后登录:2015-08-12
在线时长:0小时53分
  • 粉丝0
  • 金钱15
  • 威望0
  • 积分15

热门问题