First, function libraries and class libraries
The common library of functions in the project is to be encapsulated in the project common/function.php directly called in the project () [function ();]
The import method is thinkphp built-in class library import method, provides the convenient and flexible file import mechanism, can replace the ph require and include method completely.
For example:
Import ("MyApp.Action.UserAction");
Impot ("Think.Util.Array");
Import ("ORG. Util.page ");
Second, the right to control
Class Baseaction extends action{
Public _initialize () {
echo "Login verification First";
}
}
Class Indexaction extends baseaction{
Public Function index () {
Perform login verification before access
$this->display ();
}
}
Example::
Build a cross-project URL
__root__. " /admin.php/index/index
To determine the type of request:
$this->isget ();//Whether it is a GET request
$this->ispost ();//Whether it is a POST request
TP Hollow Operation (_empty ())
<?php
Class Cityaction extends action{
Public Function _empty ($name) {
To parse all the city's operations into the cities method
$this->city ($name);
}
Protected method
protected function City ($name) {
Echo $name;
}
}
?>
Operation of an empty module
- <? PHP
- class emptyaction extends Action{
- public function index() {
- //According to the current module name to determine the operation of the city to perform
- $cityName = module_name;
- $thisCity($cityName);
- }
- //Note the city method itself is the protected method
- protected function City($name) {
- //And $name this city-related treatment
- Echo ' current city ' . $name;
- }
- }
- ?>
Examples of using empty modules in a project:
thinkphp support for pseudo-static URL settings
' Url_html_suffix ' = '. shtml '
URL Routing
- ' url_router_on ' = = true, //Turn on routing
- ' Url_route_rules ' = = Array( //define Routing rules
- ' news/:year/:month/:d ay ' = = array(' news/archive ', ' Status=1 ' ),
- ' news/:id ' = ' news/read ',
- ' news/read/:id ' = ' /news/:1 ',
- ),
Access to LOCALHOST/TPSHOP/INDEX.PHP/NEWS/10 will access the Index/show method
TP Framework Summary (II)