thinkphp_3.1 Getting Started

Source: Internet
Author: User

Objective:

1, in order to write convenient, thinkphp below will use "TP" instead

2, before reading the article is the default reader of PHP basic syntax is more familiar.

· How do I use TP? In fact, 3 steps, the following will be introduced

1. Find the full version of thinkphp
2. Automatically generate project directory via thinkphp
3. Write code on the generated project

· Thinkphp Core Document Introduction

├─thinkphp.php Framework Portal File ├─common Framework common file ├─conf Framework configuration file ├─extend Framework Extensions directory ├─lang Core Language Pack directory ├─lib core class library directory │├─behavior core behavior class library │├─core Core base Class library │├─driver built-in driver ││├─cache built-in cache driver ││├─db built-in database driver ││├─taglib built-in tag-driven ││└─template built-in template engine-driven │└─template built-in template engine └─TPL system Template Catalog

· Build the project directory using thinkphp

Description: Simply create a new index.php file yourself as a portal file, and then reference the TP startup file. The code is as follows:

// define an app name define (' App_name ', ' demo '); // define the path to build the project define (' App_path ', './demo/'); // Introduction to the startup file require ' thinkphp/thinkphp.php ';

Project directory Structure and Description:

Demo project folder

├─common Project Common Files directory

├─conf Project configuration Directory

├─lang Project Language Directory

├─lib Project Class Library Directory

│├─action Action Class Library Directory

│├─behavior Behavior Class Library Directory

│├─model Model Class Library catalog

│└─widget Widget Class Library Directory

· Thinkphp's MVC corresponds to the directory, as follows:

M project directory/application directory/lib/modelV project directory/application directory/TplC project directory /application directory/lib/action

· TP routing pattern, there are 4 kinds of

1.PATHINFO =//domain/project name/Portal File/Module name/method name/Key 1/value 1/Key 2/value 2

2. Normal mode =//domain/project name/entry file? m= Module name &a= method name & key 1= value 1& key 2= value 2

3.REWRITE mode =//domain name/project name/Module name/method name/Key 1/value 1/Key 2/value 2

4. Compatibility mode =//domain name/project name/entry file? S= Module Name/method name/Key 1/value 1/Key 2/value 2

· How to define the method and show it through the route.

First look at TP automatically generated by the list, open the directory demo--------IndexAction.class.php, the code is as follows:
<?PHP//This class is automatically generated by the system and is intended for testing purposes onlyclassIndexactionextendsAction {
  
//This public method is the method of TP automatic generation Public functionindex () {$this->show (' <style type= "text/css" >*{padding:0; margin:0;} div{padding:4px 48px;} body{background: #fff; font- Family: "Microsoft Jas Black"; Color: #333;} h1{font-size:100px; font-weight:normal; margin-bottom:12px;} p{line-height:1.8em; font-size:36px}&LT;/STYLE&GT;&L T;div style= "padding:24px 48px;" > ); }//This is a custom method Public functionShow () {Echo"Hello,".$_get[' Name ']; }}

Call: Http://127.0.0.1/thinkPHP_test/index.php/Index/show?name= I'm xiaoming.

Detailed

1. Have you ever wondered why IndexAction.class.php this file is named this way? Because???? Action.class.php such a format is a TP-to-class file naming convention. The previous index is for which entry file.

2, the URL called above, each node is represented as follows:

Index.php is the entry file for the project,

/index represents the Index module

/show represents the Show method under the index module

? name= I'm xiaoming. The parameter under the Show method is the one in the custom method above that we get back by $_get.

thinkphp_3.1 Getting Started

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.