Original: 03-Create Model Action---user add
Registration page add.html
1<! DOCTYPE html Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >234<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">5<title>insert title here</title>67<body>8<div style= "width:400px;margin:0 Auto" >9<form action= "__url__/insert" method= "POST" >TenUser name: <input type= "text" name= "username"/><br/> OnePassword: <input type= "password" name= "password"/><br/> ANickname: <input type= "text" name= "name"/><br/> -Email:<input type= "text" name= "email"/><br/> -Activation: <input type= "Radio" name= "Active" value= "1" checked/> is <input type= "Radio" name= "active" value= "0"/> No <br/> the<input type= "Submit" value= "Login"/> -</form> -</div> -</body> +UserModel.class.php User Model Validation
<?PHPclassUsermodel extends model{//----------Form Validation//The data object is created by the $_post data submitted by the form. Need to use the system's automatic verification function, only need to define the $_validate property within the model class, is a two-dimensional array consisting of multiple validation factors. //Array (validation fields, validation rules, error prompts, [validation conditions, additional rules, validation time])//Required fields must be filled in the default 0 existence field validates the default regex regular validation by default 3 all -in-case verification protected$_validate=Array (//User Name field fields must be validated for failure message 1: Regex must be verified: Regular validation 3: All cases verifiedArray'username','require','user name must be filled in',1,'Regex',3), //User Name field validation Rule Tip 1: Must verify unique: Verify that the field is unique in the database 1: Validate when new data is addedArray'username',"','user account already exists! ',1,'Unique',1), //User Name field must verify failure message 0: field exists to verify regex: Regular validation 1: Validation when new data is addedArray'Password','require','user password must be filled in! ',0,'Regex',1), //confirm: Verify that the two fields in the form are the same, and that the validation rule defined is a field name//Array (' rpwd ', ' pwd ', ' two times password inconsistent! ', 0, ' confirm '),Array'name','require','user nickname must exist! ',1), Array ('Email','require','The mailbox cannot be empty! '), Array ('Email','Email','The mailbox format does not meet the requirements! '), //Array (' email ', ' ', ' Mailbox already exists! ', 1, ' unique ', 3),//The callback method verifies that the defined validation rule is a method of the current model class--only if the class uses theArray'Email','Checkemail','The mailbox already exists! ',1,'Callback',3), //in verifies that a defined validation rule must be an array within a scope, and active in the database indicates whether the user is activeArray'Active', Array (0,1),'note data, enabling: 1; Deactivation: 0',0,'inch'), //Array (' Password ', ' checkpwd ', ' Password format incorrect ', 0, ' function '),//The custom function verifies the password format, the CHECKPWD function can be called in common, the public ); //----field mappings to avoid exposed field information and table structure protected$_map=Array (//Map the form username to Uname,password mapping to PWD, note that you want to use the Uname,pwd field when the form is validated after mapping//problems after using uname some forms verify that you need to rewrite the regular rules yourself, instead of using direct validation on a unique framework, you need to rewrite the rules//' uname ' = ' username ',//' pwd ' = ' password ', );//Automatic completion of-----data, Login time Auto-fill, password MD5 encryption protected$_auto=Array (//Array (fill field, fill content, fill condition, attach rule)//Fill Condition 1: New data (default) 2: Update Data 3: All casesArray'Password','MD5',1,'function'), Array ('reg_date','getDate',1,'Callback') ); function GetDate () {returnDate'y-m-d h:i:s'); } function Checkemail () {$user=NewModel ('User'); if(Empty ($_post['ID'])){ if($user->getbyemail ($_post['Email'])){ return false; }Else{ return true; } }Else{ //determine if a mailbox is the same as another person's mailbox if($userwhere("id!={$_post[' id '} ' and email= ' {$_post[' email ']} '"),Find ()) { return false; }Else{ return true; } } } }?>UserAction.class.php operation
1<?PHP2 classUseractionextendsaction{3 Public functionindex () {4 $this-display ();5 6 }7 Public functionAdd () {8 $this-display ();9 }Ten One Public functionInsert () { A $m=NewUsermodel (); - //Dump ($m->create ())////if the creation failure returns false, indicating that the validation did not output an error message through the $m->geterror () - if($m->create ()) {//Validation Successful the if($m->add ()) {//determine if Add is successful - Echo"Operation successfully inserted data number is".$m->getlastinsid ();//returns the latest self-growth ID - //$this->success (' operation succeeded, insert data number: '. $uid); - } + Else{ - Echo"Create failed."$m->getdberror ();//return operational Data error SQL + } A}Else{ at Echo $m->geterror ();//return validation error message - } - - - } - } in - to?>03-Create Model Actions---user add