The YII framework must follow the creation method of its form.
The logon model error is consistent with the database operation model. The difference is that it does not interact with the database.
Is a widget. Before creating a form, complete the following code in the user control module:
Protected
-- Models
-- LoginFrom
Set the label name in this LoginFrom
/**
* Declares attribute labels.
*/
Public function attributeLabels ()
{
Return array (
'Username' => 'username ',
'Password' => 'password ',
// 'Rememberme' => 'remember me next time ',
}
Next, create a login model object.(Controllers control logon module)
$ User_login = new LoginForm ();
$ This-> render ('login', array (''=> $ user_login); // the green part must be consistent with the foreground code $ user_login.
Next, create a view.
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////
You can write this on the front-end logon page:
// Do not write an error in the green part.
<? Php $ form = $ this-> beginWidget ('cactiveform');?>
<DIV class = "to">
<SPAN class = "tol"> <A class = "v" href = "/" target = _ blank> </A> </SPAN>
</DIV>
<DIV class = "in">
<DL>
<! -- Create a tag -->
<DT> </DT>
<DD>
<! -- Create a text input box -->
</DD>
<DD class = "e"> </DD>
</DL>
<DL>
<DT> </DT>
<DD>
</DD>
<DD class = "e"> </DD>
</DL>
</DIV>
<DIV class = "su">
<SPAN> <INPUT class = "go" type = submit value = ""> </SPAN>
</DIV>
<? Php $ this-> endWidget ();?>
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /////////////
Next, we created a form to verify the data.
It has two methods: one is the save method and the other is the validate method.
The save () method for form data verification can verify the data while the data is saved (). After the verification is successful, the model's rules () method will be executed in the next step.
We can call validate () to verify the login form. This method verifies the input information. Saves the save step, and the rules method will be executed later.
Configure the verification prompt (in modle ---> loginForm)
Public function rules ()
{
Return array (
// Username and password are required
// Array ('username, password', 'required '),
// RememberMe needs to be a boolean
// Array ('rememberme', 'boolean '),
// Password needs to be authenticated
Array ('Password', 'authenticate '),
);
}
Then, add the error message on the front-end logon page.
<? Php echo $ form-> error ($ user_login, 'username')?>
<? Php echo $ form-> error ($ user_login, 'Password');?>
//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////
Use the UerIdentity component for User Authentication