Yii,model the value of the form submission

Source: Internet
Author: User
I have a login page that uses LDAP ...
Controller
Public Function Actionlogin () {        $model = new LoginForm;        If it is AJAX validation request        if (isset ($_post[' Ajax ')) && $_post[' ajax '] = = = ' LoginForm ') {            echo CA Ctiveform::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));    }

In my loginform model, I'm going to take the value of UserDomain, but it's always empty.
Class LoginForm extends Cformmodel {public $username;    Public $password;    Public $userdomain;        Private $_identity;     /** * Declares the validation rules.     * The rules state that username and password is required, * and password needs to be authenticated. */Public Function rules () {return array (//username and password is required array (' US Ername ', ' Required ', ' message ' = ' Pls Key in Your NT account. ', Array (' Password ', ' Required ', ' message ' =& Gt ' 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->_ident            ity = 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; }    }}


But I read it here in question one, it's worth it.
Username ' = = String ' Dasdasda ' (length=8)
' Password ' = String ' asdasdasd ' (length=9)
' UserDomain ' = String ' xxxxx ' (length=5)


Reply to discussion (solution)

I'll check it out a little bit more carefully.
UserDomain has been passed to model.
But I uploaded it from model to component/useridentity without userdomain/.

Here's the problem.
The Cuseridentity constructor
By default only constructs Username,password ...
So you can't pass the value to cuseridentity.
A method must be defined inside the component/useridentity.
Pass the UserDomain in.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.