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:
<?php
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:
Url:localhost/thinkphp/admin.php?m=show&a=add
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:
<?php
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:
Tpl/show/cc.html
The code is as follows:
The above is the entire content of this article, I hope you can enjoy.