20150314--tp-01

Source: Internet
Author: User

Catalogue

First, Introduction 2

1. What is thinkphp 2

2. What is frame 2

3. What is MVC 2

4. Introduction thinkphp 3

5. Quick Start 4

Second, Controller 9

1. What is a controller 9

2. Defining a controller 9

3. URL Dispatch Mode 10

4. NULL Operation 12

5. Empty Module 13

6. Project Grouping 15

7. URL Case 16

8. page Jump 16

9. page Redirection 17

Third, views 18

1. What is view 18

2. Template Definition 18

3. delimiter 18

4. template Assignment and output 18

5. Template string Substitution 19

6. Get content 20

First, Introduction

1. What is thinkphp

It's an MVC framework

2. What is a framework

Framework, which is the frame. is actually an application of semi-finished products, is a set of components, for you to choose to complete your own system.

L Zend Framework

• YII

L Symfony

L Codelgniter

L thinkphp

L ...

3. What is MVC

MVC is a software design pattern invented by Xerox Parker Research Center (Xerox PARC) in the 80 's for programming language Smalltalk-80, which has been widely used so far.

MVC is a design pattern that makes it mandatory to separate the input, processing, and output of an application. Using an MVC application is divided into three core parts: model, view, controller.

M:model model

V:view View

C:control Controller

Quick Start

Controller

View

Model

Useful items

4. Introduction thinkphp

L http://thinkphp.cn

L Download thinkphp3.0

L deploy directly to the project

L php5.2

thinkphp1.0 php5.0

thinkphp3.0 php5.2

thinkphp3.2.2 php5.3

Project deployment process:

1) Unzip the thinkphp and go to the extracted folder

2) put the thinkphp folder in our project

5. Quick Start

1) Development Project entry file

2) Run the above program, automatically create the corresponding program files

See the above interface to show that the project was created successfully

In our project, some folders are generated automatically, as shown in:

L Common Project Public file directory

L Conf Project configuration directory

L Lang Project Language Pack Directory

L LIB Project Class Library Directory

L TPL Project Template Catalog

L Runtime project run-time catalog

L ~runtime.php This file will automatically compile the project's current configuration, public functions and other programs into this file, the next time the program runs, run the file directly.

Index in the above URL will be automatically processed as the module name

The index in the above URL will be automatically processed as the action name

3) Turn on debug mode

Code:

Run:

After you turn on debug mode, if some errors occur, there are some hints that suggest:

When developing, turn on debug mode

Switch off the debug mode when

If your project path is the same as the subject, you can not define three path constants

Note: runtime.php files are not generated when debugging is turned on

4) Analysis of Project entry file

5) Default configuration

Why you can see the content after you enter the address

The index method under the Index module controller is automatically loaded because the above URL is enabled

In a framework configuration file, copy the two configuration options

Place the above options in the project configuration file

6) Add a new controller and method

Create a new controller under Lib/action goodsaction

Adding a new method in Goodsaction add

Run the above program:

Adds the specified template to the Add method and displays

One project corresponds to a database

A database contains a large number of data tables

A data table is a module

A module can correspond to a controller

Create a goods folder under TPL to hold the template under all goods modules

To modify the controller code:

Run:

7) Configure the project's virtual host

To modify the Apache configuration file:

To modify the Hosts file:

Restart Apache and rerun:

Second, the controller

1, what is the controller

Controller is used to receive and process user requests

2. Define the Controller

Create a controller file under Lib/action

File name: module name (capital letter) Action.class.php

For example: We have a data sheet: Member, membership form

/lib/action/memberaction.class.php

Controller content:

class module name (first capitalization) Action extends action{

}

Parent class controller action must be inherited

Code:

20150314--tp-01

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.