我有一个登录页面,用的是ldap...
controller
public function actionlogin() { $model = new loginform; // if it is ajax validation request if (isset($_post['ajax']) && $_post['ajax'] === 'loginform') { echo cactiveform::validate($model); yii::app()->end(); } if (isset($_post['loginform'])) { $model->attributes = $_post['loginform']; var_dump($model->attributes); //question one if ($model->validate() && $model->login()) { $this->redirect(array('form/index')); } } $this->render('login', array('model' => $model)); }
我的loginform model里面,我要取userdomain的值,但是一直为空
class loginform extends cformmodel { public $username; public $password; public $userdomain; 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( // username and password are required array('username', 'required', 'message' => 'pls key in your nt account.'), array('password', 'required', 'message' => 'pls key in your nt password.'), array('userdomain', 'required', 'message' => 'pls select your domain host.'), // password needs to be authenticated array('password', 'authenticate'), ); } /** * declares attribute labels. */ public function attributelabels() { return array( 'userdomain'=>'user domain', ); } /** * 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, $this->userdomain); if (!$this->_identity->authenticate()) $this->adderror('password', 'incorrect username or 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->userdomain); $this->_identity->authenticate(); } if ($this->_identity->errorcode === useridentity::error_none) { return true; } else { return false; } }}
但是我在question one这里读取来是有值的
username' => string 'dasdasda' (length=8)
'password' => string 'asdasdasd' (length=9)
'userdomain' => string 'xxxxx' (length=5)
回复讨论(解决方案) 我再仔细查咯一下..
userdomain已经传给model咯..
但是我从model里面传到component / useridentity的没有userdomain/
问题出在这里
cuseridentity的构造函数
默认只有构造username,password...
所以不能传值给cuseridentity.
必须在component / useridentity里面再定义一个方法..
把userdomain给传递进去