Installation configuration of thinkphp Learning notes

Source: Internet
Author: User
Tags lowercase require

This article mainly introduces a domestic MVC framework thinkphp, here is the thinkphp installation and configuration, as well as a simple example, the need for small partners can refer to.


The thinkphp framework is an MVC framework that initially simulates the Java Struts framework, uses a single entry file to simulate Java filters, and uses action to simulate struts controller action, so why is it that in his MVC, M is model,v is view, and control is the cause of action.

In version 3.2.3, the control was changed to C, and it tended to form, because the SPRINGMVC of the Java World began to become popular, and spring used control, which did not use the definition of action, in fact, the action to indicate control itself is a certain misleading, control on C Well, why a aciton, let a person not touch the mind.

Thinkphp the most difficult to understand is his access, in the official document explained a bit misleading, according to Guanven must be wrong, because Guanven did not speak clearly!

thinkphp installation is actually very simple, as long as require his main program files, you can generate some columns of the directory, but the URL and his control, TPL's relationship is what? Guanven said it is too vague, whenever the use of Java people will be the official text to vomit blood!

Guanven, can you be more organized?

After actual use, the following points are summarized:

1, install thinkphp:

and the main program thinkphp the same directory to create admin.php or other names can be

The code is as follows:
Define project name and path
Define (' app_name ', '); Name time and space, is the generated folder before the prefix
Define (' App_path ', './admin/');//This is the meaning of generating the admin directory under the same directory as the main program thinkphp
Define (' App_debug ', true);/start edit mode, File Force compilation, do not cache
Load Frame Entry file
Require (".. /thinkphp/thinkphp.php ");//Main program entry file

2, File directory:

The automatically generated file directory is

Common: Where to write functions

Conf: Configuration files, such as configuring database connection addresses

Lang: Language packs, internationalization

Lib:action,model are all in here, is a more important place, and Java Lib is a jar package completely different concept

Runtime: Cached files at run time

TPL: template, HTML file

3, access method:


Explanation: Local/project directory/The single entry file just created? Model= class name &action= method name

Add method in show class in admin.php of single entry file

Emphasis: Class name is the beginning of uppercase, lowercase will not find, this put me to the bitter, and made a afternoon, the original is only recognized capital class name, lowercase do not know

InfoPath style Url:localhost/thinkphp/admin.php/show/add

Explanation: The same as the default, is not write M A

4, write class, write method:

Thinkphp's author must be a person who likes to toss, perfectionist, so will think out this way to control program, the whole process is to action class as the core, an action class equals is a page, the inside method is and this page related operation, what additions and deletions change check ah, This is in line with the Chinese way of thinking, but the reusability is not high.

Write file: lib/action/showaction.class.php

The code is as follows:
Show is the class name, action is only a recognition aid, must write, but can be invoked when ignored, remember uppercase Oh, you lowercase he also gave you a capital to start, so you can not find a lowercase show module, m=show
Class Showaction extends Action {
Add is the action method, A=add
Public function Add () {
Output page cc, he automatically loads the default TPL directory under the show file under the cc.html file, where there is no cc, the Load method name of the same add.html, if cc.html and add.html have no error
$this->display (' cc ');

5, write the template:

The above mentioned the load template, now write a:


The code is as follows:

The above is the entire content of this article, I hope you can enjoy.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.