Yii YII widget create logon Form Login form

Source: Internet
Author: User

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

 

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.