ThinkPHP3.2 Basic Tutorial (--url) operation

Source: Internet
Author: User
Tags naming convention subdomain

URL case

The system default specification is based on the module name inside the URL, the controller name to locate the specific controller class, thereby executing the Controller class operation method.

If it is a Windows environment, regardless of how the case can be located, if in the Linux environment, once the case is inconsistent, it will occur in the URL using the lowercase module name can not find the module class. However, the system itself provides a case-insensitive solution that can be configured with a simple implementation.

As long as in the project configuration, add:

' Url_case_insensitive ' =true

Once configured, URL access is no longer case sensitive, even under the Linux environment.

There is a place to note that once the URL case is turned off, if we want to access a controller like Usertypecontroller, then the correct URL access should be:

// correct access address http://servername/index.php/home/user_type/index//Error Access address (in Linux environment)http:   Servername/index.php/home/usertype/index

If you set

' Url_case_insensitive ' =false

The URL then becomes: http://serverName/index.php/Home/UserType/add

Note: The URL is case-insensitive and does not change the naming specification of the system, and the URL is not case-sensitive unless the system's naming convention is followed correctly.


URL pseudo-static is usually to meet the better SEO effect, thinkphp support pseudo-static URL settings, you can set the Url_html_suffix parameter arbitrarily at the end of the URL to add the static suffix you want, without affecting the normal execution of the current operation. For example, we set up

    ' Url_html_suffix ' = ' shtml '

We can turn the following URL http://serverName/Home/Blog/read/id/1 into http://serverName/Home/Blog/read/id/1.shtml, which has the URL feature of a static page , but has the same execution effect as the previous URL, and does not affect the use of the original parameter.

By default, pseudo-static is set to HTML, and if we set the pseudo-static suffix to null,

' Url_html_suffix ' and ' = '

All static suffixes can be supported, and the current pseudo-static suffix is logged to the constant __ext__, but does not affect normal page access.

If you want to support multiple pseudo-static suffixes, you can set the following directly:

// multiple pseudo-static suffixes set with | split

You can set a URL suffix that is forbidden, for example:

// URL-Forbidden suffix setting

  Note: The Url_deny_suffix priority is higher than the url_html_suffix.

URL generation

In order to match the URL pattern used, we need to be able to dynamically generate the corresponding URL address according to the current URL settings, for this reason, thinkphp built-in provides a U method for the dynamic generation of URLs to ensure that the project is not affected by the environment during the migration process.

  Defining rules

The definition rules for the U method are as follows (the parameters in square brackets are determined according to the actual application):

    U (' address expression ', [' parameter '],[' pseudo static suffix '],[' Display domain name '])

    Address expression

The format of an address expression is defined as follows:

[module/controller/Operation # anchor point @ domain name]? parameter 1= value 1& parameter 2= value 2 ...

If you do not define a module, it represents the current module name, here are some simple examples:

// the URL address of the add operation that generated the user controller // generate a read operation for the blog controller and a URL address with ID 1 // URL Address of the select operation of the user controller that generated the admin module


The second parameter of the U method supports both the array and the string definitions, if only a string-like argument can be defined in the first parameter, for example:

U (' blog/cate ',array(' cate_id ' =>1, ' status ' =>1)) u (' blog/cate ', ' Cate_id=1&status=1 ' ) U (' Blog/cate?cate_id=1&status=1 ')

The three methods are equivalent, all of which generate the Cate operation of the blog controller and cate_id a URL address of 1 status 1. However, the following definitions are not allowed to be used to pass parameters.

U (' blog/cate/cate_id/1/status/1 ');

  Automatic recognition

Depending on the URL settings of the project, the same U method call can intelligently correspond to different URL address effects, for example:

U (' blog/read?id=1 ');
http://servername/index.php?m=blog&a=read&id=1//url set to normal mode http://  SERVERNAME/INDEX.PHP/HOME/BLOG/READ/ID/1//url set to PathInfo mode http://servername/home/blog/read/ ID/1//url set to rewrite mode http://servername/home/blog/read/id/1.html//url set rewrite mode, and set the pseudo-static suffix to. html

If Url_case_insensitive is turned on, a lowercase URL address is generated uniformly.

  Generate Routing Address

The U method can also support routing if we define a routing rule as:

' news/:id\d ' = ' news/read '

Then you can use

U ('/news/1 ');

The resulting URL address is:


Note: If you are using the U method directly in the template file, you need to take the {: U (' parameter 1 ', ' parameter 2 ' ...)} method.

  Domain Support

If your application involves multiple subdomains, you can also specify the domain name in the U method that you want to generate the address for, for example:

U (' blog/[email protected] ', ' id=1 ');

After the @ is passed in to the domain name you want to specify. The system will automatically determine whether the SSL protocol is currently being generated and https://.

In addition, the 4th parameter of the U method, if set to true, indicates that the current domain name is automatically recognized and automatically matches the subdomain that generated the current address according to the subdomain deployment settings App_sub_domain_deploy and App_sub_domain_rules automatically.

  Anchor Point Support

    The U function can directly generate an anchor point in the URL address, for example:

U (' blog/read#comment?id=1 ');

The resulting URL address might be:



ThinkPHP3.2 Basic Tutorial (--url) Action

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.

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.