YiiYII widget create Login form _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The yiiYII widget creates a Login form. The YII Framework must follow the creation method of its form to create a logon model. the error is the same as that of the database operation model. The difference is that it does not interact with the database and uses widgets, before creating a form, 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.

BeginWidget ('cactiveform');?>






LabelEx ($ user_login, 'Username');?>



TextField ($ user_login, 'username', array ('size' => 25, 'class' => 'inputbg () ');?>




LabelEx ($ user_password, 'password');?>


TextField ($ user_password, 'password', array ('size' => 25, 'class' => 'inputbg () ');?>








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
'Username required '),


'Password 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.

Error ($ user_login, 'Username')?>

Error ($ user_login, 'password');?>

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////

Use the UerIdentity component for user authentication

The wrong login model of Butler is consistent with the database operation model. The difference is that it does not interact with the database and uses widgets. before creating a form...

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.