Thinkphp three automatic introduction, thinkphp three introduction _php tutorial

Source: Internet
Author: User

Thinkphp three automatic introduction, thinkphp three major introduction


This article tells the thinkphp in detail the three big automatic, is very important application, shares for everybody for everybody reference. Specific as follows:

First, automatic verification

The format is as follows:

Parameter description:

Validation field: Need to verify form field name
Validation rules: Must be used in conjunction with additional rules
Error message: If an error occurs, what kind of error message is thrown to inform the user
Verification conditions: 0, 1, 2
Additional rules: 1, Regex uses regular validation 2, function validation 3, callback callback 4, confirm verify two fields in the form 5, verify that equals a value of 6, in is within a range of 7, verify whether unique
TP Package: Require field must be verified; eamil verification mailbox; URL authentication URL address; currency currency; number;
Validation time: Refers to the database operation time validation time, the new data validation model::model_insert, editing the time to verify the model::model_update; Verify the model::model_both in all cases;

The aoli/home/tpl/default/user/reg.html page is as follows:

The aoli/home/lib/model/usermodel.class.php page is as follows:

<?phpclass Usermodel extends model{//the table in the corresponding database user  protected $_validate=array (     Array (' username ', ' Require ', ' username required '),     Array (' username ', ' checklen ', ' User name length too long or too short ', 0, ' callback '),     Array (' Password ', ' require ', ' Password required '),     array (' Repassword ', ' require ', ' duplicate password required '),     Array (' Password ', ' Repassword ', ' two times password inconsistent ', 0, ' confirm '),     Array (' createtime ', ' number ', ' You are not entering numbers '),     array (' Createip ', ' email ', ' mailbox format is incorrect ')  ;   function Checklen ($data) {    if (strlen ($data) >15 | | strlen ($DATA) <5) {      return false;    } else{      return True;}}      ? >

The aoli/home/lib/action/useraction.class.php page is as follows:

<?php class Useraction extends Action {function Reg () {   $this->display ()} function Regadd () {   $user =d (' User ');   if ($user->create ()) {     if ($user->add ()) {       $this->success (' registered success ');     } else{       $this->error (' registration failed ');     }   } else{     $this->error ($user->geterror ());   }  

II. Automatic completion (auto-fill)

Auto-Completion is also a member of the Thinkphp method, which is automatically executed when create

The rules are as follows:

Array (' Fill field ', ' Fill content ', ' Fill condition ', ' additional rules ');

A simple example is as follows:

Protected $_auto = Array (    //array (' status ', ' 1 '),  //Added when the Status field is set to 1   array (' Password ', ' MD5 ', 1, ' function '),//To the password field in the new time when the MD5 functions are processed   

Second, automatic Mapping (field mapping)

Auto Map: maps The fields of the database to aliases, and aliases are available in the form .

A simple example is as follows:

Protected $_map = Array (    ' name ' = ' username ',  

The techniques described in this article will help you learn and use thinkphp.


THINKPHP313 can not load functions automatically

The problem of caching, immediately open the debug sometimes, the runtime folder is deleted, if you log in, please exit and then login.

thinkphp Automatic Verification

You remove $this->error (), $User->geterror () to output. Because you have shown above, blocking the back of the display. The error message is displayed by GetError ().

http://www.bkjia.com/PHPjc/868245.html www.bkjia.com true http://www.bkjia.com/PHPjc/868245.html techarticle thinkphp Three automatic introduction, thinkphp Three brief introduction of this article in more detail about the thinkphp in the three automatic, is very important application, share for everyone for reference. Specific as ...

  • 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.