Index. php,

Source: Internet
Author: User

Index. php,

Index. php

 

<? Php // define the PATH in which the ThinkPHP framework stores define ('Think _ path ','. /ThinkPHP/'); // defines the NAME of the current project. The project here can be understood as the define ('app _ name', 'protal') of the module home '); // define the project PATH define ('app _ path ','. /protal/'); define ('app _ debug', true); require THINK_PATH. 'thinkphp. php ';


Conf/config. php

<? Php // contains the configuration file $ dbConf = include that defines the configuration of database connection '. /config. inc. php '; // define the general configuration of the project itself $ Conf = array (// 'config maps' => 'configuration value' URL _ model' => 2, // 2 indicates the URL rewrite mode); return array_merge ($ dbConf, $ Conf);?>


 

 

 

 

There is a configuration file config. inc. php at the same level as the entry file.

 

 

<? Phpreturn array (// 'config map '=> 'configuration value' 'db _ type' => 'mysql', 'db _ host' => 'localhost ', // database NAME 'db _ name' => 'think', // Database USER 'db _ user' => 'root ', // Database Password 'db _ pwd' => '', // database PORT 'db _ port' => '123 ', // table PREFIX 'db _ prefix' => 't_',)?>


Controller IndexAction. class. php

 

<? Php // This class is automatically generated by the system and is for test purposes only. class IndexAction extends Action {public function index () {header ("Content-Type: text/html; charset = UTF-8 "); $ this-> display (" reg ");} function add () {if (md5 ($ _ POST ['verify '])! = $ _ SESSION ['verify ']) {$ this-> error ("Verification code error");} // instantiate the custom Model M ('user ') instantiate basic model $ user = D ("User"); if ($ user-> create () {// execute the insert operation. After successful execution, returns the newly inserted Database ID if ($ user-> add () {$ this-> success ("registered successfully ");} else {$ this-> error ("registration failed ");}} else {// display the error message $ this-> error ($ user-> getError () ;}// generate the image verification code function verify () {/*** how to implement the verification code in thinkPHP *** ThinkPHP has provided us with the image processing class library ThinkPHP \ Extend \... ** how to import a class library? * The import class library uses "import (file path) for import, but note that \ in the file path should be replaced. "* 1) import the system class library import (starting from the library) import ('org. util. image ') note case sensitivity * 2) import the project class library import ("@. ORG. image ") We need to store * // import graphics processing class library import (" ORG. util. image "); // import ("@. ORG. image "); // generate a graphic verification code/* length: the length of the verification code. The default value is 4-digit mode: the type of the verification string. The default value is a number, other supported types include 0 letters, 1 digit, 2 capital letters, 3 lowercase letters, 4 Chinese characters, and 5 characters (removed confusing characters oOLl and numbers 01). type: The image type of the verification code, the default value is png width: The Verification Code width. By default, height is automatically calculated based on the verification code length. The default value is 22 verifyName: The SESSION Record Name of the verification code, the default value is verify * // The English Verification Code image: buildImageVerify (, 'gif', 60, 22, 'verify '). // The Chinese verification code is implemented. // image :: GBVerify ();}}


 

Model UserModel. class. php

 

<? Phpclass UserModel extends Model {// automatically verifies protected $ _ validate = array (// detailed verification content for each field array ("username", "require ", "username cannot be blank"), array ("username", "checkLength", "username length does not meet requirements", 0, 'callback'), array ("password ", "require", "the password cannot be blank"), array ("password", "checkLength", "the password length requirement is 5 ~ ", 0, 'callback'), array (" password "," repassword "," two different passwords ", 0, 'Confirm '), array ("qq", "require", "qq is required"), // array ("cdate", "require", "time cannot be blank ", callback),); // automatically fills in protected $ _ auto = array ("password", "md5", 3, 'function'), array ("cdate ", "shijian", 3, 'callback'), array ("dizhi", "getIp", 3, 'callback'),); // custom verification method, to verify whether the length of the user name is valid. // $ date can be written as any parameter, for example, $ AA $ bbfunction checkLength ($ data) {// $ data stores the string if (strlen ($ data) <5 | strlen ($ data)> 15) {return false ;} else {return true ;}// return the visitor's IP address function getIp () {return $ _ SERVER ['remote _ ADDR '];} function shijian () {return date ("Y-m-d H: I: s ");}}


 

Template reg.html

 

<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 


 

 

If you still have any questions, please leave me a message. I will answer your questions in detail. Thank you for your attention.

 

 

 

 

 

The directory structure is as follows:

 

TP

-------- ThinkPHP folder

-------- The file protal. php is called protal. php.

 

When you run protal. php, the welcome page of ThinkPHP appears, proving that the configuration is successful, and the Directory results will change.

The directory is

 

TP

-------- ThinkPHP folder

-------- Protal. php entry file (the file above)

-------- Protal folder

 

 

The generated project directory structure is similar to the system directory, including:

 

Common

Project Public file directory, generally placed in the project's public functions

Conf

Project configuration directory, where all configuration files of the project are stored

Lang

Project Language Pack directory (optional, can be deleted if you do not need multiple languages)

Lib

The project class library directory, usually including the Action and Model subdirectories.

Tpl

Project template directory, supporting template themes

Runtime

Project runtime directory, including Cache (template Cache), Temp (Data Cache), Data (Data directory), and Logs (Log File) subdirectories. If there are groups, the first is the group directory.

 

 

 

 

 

 

Mysql>SELECT FROM_UNIXTIME (875996580 );

-> '2017-10-04 22:23:00'

 

 

Mysql>SELECT UNIXTIME_TIMESTAMP ('2017-10-04 22:23:00 ');

->'875996580'

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.