无法给attributes赋值,求解决。求高手指点 [ 1.1 版本 ]
$loginForm=new LoginForm;//loginForm模型是Yii提供的登陆验证模型
if(isset($_POST['LoginForm'])){
$loginForm->attributes=$_POST['LoginFrom'];//将表单数据提交给一个变量集合
var_dump($loginForm->attributes);
exit;
if($loginForm->validate()){//开始验证提交的变量
    echo '111111';
}
}
已经解决了,赋值的时候变量写错了,谢谢大家关注
共 2 个回答
- 

你的 LoginForm 内容贴上来。
共 2 条回复
        <?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;}
elsereturn false;}
} 
 - 
qyt1988528 回答于 2015-06-02 14:43 举报我是新手,我都是这么写
$loginForm->attributes = array( 'username' => $_POST['username'], 'password' => $_POST['password'], ..... );赋值完是不是要保存一下 $loginForm->save();
var_dump($loginForm); 试试共 1 条回复 
zhang1989
            注册时间:2015-06-01
最后登录:2015-08-12
在线时长:0小时53分
    最后登录:2015-08-12
在线时长:0小时53分
- 粉丝0
 - 金钱15
 - 威望0
 - 积分15