thinkphp Study Notes installation configuration _php Tutorial

Source: Internet
Author: User

thinkphp Study Notes installation and configuration Chapter


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 homegrown framework, thinkphp, is an MVC framework that initially simulates the Java Struts framework, simulates Java's filters using a single portal file, and uses action to emulate struts's controller action, so why is his MVC M is model,v is view, and control is the cause of action.

In 3.2.3, control changed to C, is also tending to form, because the Java World Springmvc began to popular, spring used by the control, not the use of the definition of action, in fact, the action to indicate that control itself is somewhat misleading, control on C Well, why a aciton, let a person can not touch the mind.

Thinkphp the most difficult to understand is his way of access, in the official documents on a bit misleading, according to frustration must be wrong, because frustration didn't speak clearly!

thinkphp installation is actually very simple, as long as require his main program file, you can generate some columns of the directory, but the URL and his control, TPL relationship is what? Frustration said too vague, anyone who has used Java will be the official text to spit blood!

Frustration, can you clear the order?

The following points are summarized after actual use:

1, install thinkphp:

It is possible to create admin.php or other names in the same directory as the main program thinkphp.

The code is as follows:


Define the project name and path
Define (' app_name ', '); Name space time, is the generated folder before the prefix is not added
Define (' App_path ', './admin/');//This is the same as the main program thinkphp the same directory to generate the admin directory meaning
Define (' App_debug ', true);//start edit mode, file forced compilation, do not cache
Loading 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 configuration database connection addresses

Lang: Language Pack, internationalization

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

Runtime: Cache file at runtime

TPL: template, which is HTML file

3, access method:

Url:localhost/thinkphp/admin.php?m=show&a=add

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

Meaning: Enter the Add method in the show class in the single entry file admin.php

Emphasis: The class name is the beginning of the uppercase, lowercase will not find, this hurt me, got an afternoon, the original is only known capitalization class name, lowercase do not know

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

Explanation: As with the default, it is not written out M A

4, write the class, write the method:

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

Writing files: lib/action/showaction.class.php

The code is as follows:


Show is the class name, the action is only a recognition aid, must write, but can be called when ignored, remember to capitalize oh, you lowercase he also give you a capital start, let you kill not find the module of the lowercase Show, m=show
Class Showaction extends Action {
Add is the action method, A=add
Public function Add () {
Output page cc, he automatically load the default TPL directory under the show file Cc.html file, if there is no cc, 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 loading template, now write one:

Tpl/show/cc.html

The code is as follows:


A plain HTML file

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

http://www.bkjia.com/PHPjc/963994.html www.bkjia.com true http://www.bkjia.com/PHPjc/963994.html techarticle thinkphp Study Note Installation Configuration 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 ...

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