I. Getting Started and installing
1. Add to the Hosts file that enters C:\Windows\System32\drivers\etc
127.0.0.1 www.tp5.com
Access to this domain is equivalent to accessing 127.0.0.1
2. Modifying the Apache configuration file
Increase
<virtualhost ~e42e:80>documentroot "/home/www/tp5/public" <br/>servername tp5.com<br/></ Virtualhost>
This means that access to the www.tp5.com system is automatically directed to this public directory
3.requery modules are those that handle $_get and $_post () built-in request objects that are behind the address bar
4. Why the access is under public, but can be recognized under the app, because there is a static file under public
<ifmodule mod_rewrite.c>options +followsymlinks-multiviewsrewriteengine OnRewriteCond%{REQUEST_FILENAME}!- Drewritecond%{request_filename}!-frewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]</ifmodule>
Two. Routing Learning
1. Default access Mode
1) http:/hostname/Pathname Entry file Module controller operation
Http://localhost/test/index.php/index/index/index
2) URL Access path size:
Host is converted to lowercase;
The controller initial letter is automatically capitalized;
3) Controller for hump type HelloWorld
Visit time
Http://localhost/test/index.php/index/hello_world/index
4) If you want to access HelloWorld with HelloWorld, Url_convert = False
5) Second way of access
Http://localhost/test/index.php?s=index/index/index
6) Now TP5 only supports both of these methods
2. Parameters passed in
1) Default incoming mode: parameters can be arbitrarily passed in, variable parsing does not value order.
2) If you want to omit the incoming words, change the parameter Url_param_type = 1
3) The value can now be passed strictly in the order in which the operation method is defined.
http://localhost/test/index.php/index/index/shanghai/thinkphp
Do not pass variable names
Http://localhost/test/index.php/index/index?name=thinkphp&city=shanghai
3 Hidden index.php
1) tp5 default in the app directory there is a. htaccess file, automatically hidden, of course, under the Apache server.
2) If the phpstudy is used, the rules are as follows:
<ifmodule mod_rewrite.c> Options +followsymlinks-multiviewsrewriteengine onrewritecond%{REQUEST_FILENAME}!-d Rewritecond%{request_filename}!-f rewriterule ^ (. *) $ index.php [l,e=path_info:$1] </IfModule>
3) If you are using an Apache version that does not hide index.php properly using the above method, you can try to configure the. htaccess file using the following method.
<ifmodule mod_rewrite.c>options +followsymlinks-multiviewsrewriteengine onRewriteCond%{REQUEST_FILENAME}!- Drewritecond%{request_filename}!-frewriterule ^ (. *) $ index.php?/$1 [qsa,pt,l]</ifmodule>
4) If it's an nginx server,
Location/{//... Omit part of the code if (!-e $request _filename) { rewrite ^ (. *) $ /index.php?s=/$1 last; } }
4. Defining routes
The main reason to define the route is to facilitate SEO optimization, after all, TP5 's default access is through multiple/to access the
Add some routing rules inside the route.php, after defining the routing rule, the original URL address will be invalidated and become an illegal request.
1)
Written in this return.
return [
Add a routing rule to the index controller's Hello action method
' Hello/:name ' = ' Index/index/hello '
]
Use [Enclose the]:name, you can not write
2)
The second method for defining routes, written at the beginning of the route.php
Use Think\route;
Route::rule (' Hello/:name ', ' Index/index/hello ')
3) Too many parameters in the configuration file set Pathinfo_depr = '-', the other line, Easy SEO optimization
5. Generate URL addresses for easy reference to URLs
1) use Url::build () or URL () to generate the URL address, the proposed URL, the following four ways to output the same result
Url::build ("Url2", "a=1&b=2");
URL ("Url2", "a=1&b=2");
URL ("Url2", ["a" = "1", "B" = "2"]);
URL ("Url2", Array ("a" = "1", "B" = "2"));
2) "Url2", written in this way, will default to refer to the current method under the current controller under the current module
3) URL ("Admin/hello/index", "a=1&b=2"), which generates the index operation under the Hello Controller under the admin module
4) URL (today/2017/20) routing rule, which generates the corresponding URL address
5) If the Url_html_suffix parameter is set, the generated URL will be appended with the suffix .
' Url_html_suffix ' = ' html '
thinkphp Study Notes (i)