Home  >  Article  >  Backend Development  >  yii YII widget creates login form form Login form_PHP tutorial

yii YII widget creates login form form Login form_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:36711browse

YII框架必须遵循其表单的创建方法

登录模型错做与数据库操作模型是一致的,不同的是不跟数据库交互

,用的是小部件,在创建表单之前,要在用户控制模块完成以下代码

protected

  --models

      --LoginFrom

在这个LoginFrom里面设置标签名

/**
     * Declares attribute labels.
     */
    public function attributeLabels()
    {
        return array(
            'username'=>'用户名',
            'password'=>'密      码',
            //'rememberMe'=>'Remember me next time',
        }

  接下来创建登陆模型对象(controllers 控制登录模块)
            $user_login=new LoginForm();
            $this ->render('login',array(''=>$user_login));//绿色部分和前台代码$user_login 要一致

 接下来创建view视图

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

在前台登录页面可以这么写:

//绿色部分注意不要写错

beginWidget('CActiveForm'); ?>
                


                    
                

                

                    

                        
                        

                        

                        
                          
                        

                        

                    

                    

                        

                        

                      
                        

                        

                    


                

                

                    
                

  endWidget(); ?>

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

Next, create the verification of the form data

It has two methods, one is the save method and the other is the validate method

The form data validation save() method can verify the data at the same time. If the verification is successful, the data can be stored in save(). There will be a step later that will execute the rules() method of the model, which is to verify the form

We are now using to implement the verification of the login form. We can call validate(). This method verifies the information we entered. This saves the save step, and the rules method will also be executed later

Configure verification prompt information (in model--->loginForm)

public function rules()
                                                                                                                                         Username required'),


  

                                                                                                         ), > // Remembermene to be a Boolean
// Array ('Rememberme ",' Boolean '), // Password Needs to be authenticated
Array (' Password ', 'Authenticate '),
);
}



Then add an error message to the front-end login interface

error($user_login,'username')?>

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

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

Use UerIdentity component for user verification

http://www.bkjia.com/PHPjc/750418.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/750418.htmlTechArticleYII framework must follow the creation method of its form. The login model is consistent with the database operation model. The difference is that It does not interact with the database, but uses widgets. Before creating the form...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn