A method
A method is used to instantiate the controller internally, calling the format: A (' [Project://][Group/] module ', ' Controller layer name ')
The simplest usage:
Copy Code code as follows:
Represents the Useraction controller that instantiates the current project (the corresponding file for this controller is located in Lib/action/useraction.class.), if grouping mode is used, and the controller to instantiate another admin group can use:
Copy Code code as follows:
$User = A (' Admin/user ');
Cross-project instantiation is also supported (the Directory of the project is to be sibling)
Copy Code code as follows:
$User = A (' Admin://user ');
Represents the Useraction controller under the instantiated Admin project
The. 1 version adds support for a tiered controller, so you can also instantiate other controllers with the A method, for example:
Copy Code code as follows:
$User = A (' User ', ' Event ');
Instantiate the Userevent controller (the corresponding file is located in Lib/event/userevent.class.).
After instantiating the controller, you can invoke the method in the controller, but it should be noted that, in the case of cross project invocation, if your method of operation has special variable operations against the current controller, there will be some unknown problems, so, in general, the official recommendation requires a common call to the controller layer to be developed separately, Don't have too many dependencies.
B method
This is a newborn function that comes into being as a behavior, and can perform an action such as
Copy Code code as follows:
is to perform all the functions defined by this behavior before the project begins. Supports 2 parameters, and the second parameter supports the need to accept an array, for example
Copy Code code as follows:
B (' App_begin ', Array ("name" =& gt; " Tdweb "," Time "=>time ());
C method
The C method is a method that you can use to set up, get, and save configuration parameters with a high frequency.
Understanding the C method requires understanding the configuration of the next look first, because all operations of the C method are related to configuration. The configuration file for the I/A is defined by array format.
Because of the use of function overload design, so the use of more, we come to one by one notes.
Setting parameters
Copy Code code as follows:
C (' db_name ', ' to be ');
Indicates that the value for setting the db_name configuration parameter is "I", because the configuration parameters are case-insensitive, so the following writing is the same:
Copy Code code as follows:
C (' db_name ', ' to be ');
However, it is recommended that you maintain a uniform capitalization configuration definition specification.
All parameters of a project can be dynamically changed by this method before it takes effect, and the last set value overrides the definition in the previous or custom configuration, or you can add a new configuration using the parameter configuration method.
Supports the settings for level two configuration parameters, such as:
Copy Code code as follows:
C (' USER. USER_ID ', 8);
Configuration parameters do not recommend more than two levels.
If you want to set multiple parameters, you can use the batch setting, for example:
Copy Code code as follows:
$config [' user_id '] = 1;
$config [' user_type '] = 1;
C ($config);
If the first parameter of the C method passes in an array, it represents a bulk assignment, which is equivalent to the following assignment:
Copy Code code as follows:
C (' user_id ', 1);
C (' User_type ', 1);
Get parameters
To get the parameters of the setting, you can use:
Copy Code code as follows:
$userId = C (' user_id ');
$userType = C (' User_type ');
Returns null if the USER_ID parameter has not been defined.
You can also support obtaining level two configuration parameters, such as:
Copy Code code as follows:
$userId = C (' USER. User_ID ');
If the incoming configuration parameter is empty, the parameters are obtained:
Copy Code code as follows:
Save Settings
The. 1 version adds a feature that permanently saves settings parameters, only for bulk assignments, such as:
Copy Code code as follows:
$config [' user_id '] = 1;
$config [' user_type '] = 1;
C ($config, ' name ');
After the config parameter is set in bulk, it is saved to the cached file (or other configured caching mode) along with all current configuration parameters.
After saving, if you want to retrieve the saved parameters, you can use the
Copy Code code as follows:
$config = C (', ' name ');
Where name is the identity of the cache used to save the parameter earlier, it must be consistent to retrieve the saved parameters correctly. The retrieved parameters are merged with the current configuration parameters and do not need to be manually merged.
D method
D method should be used more methods, used to instantiate the custom model class, is a think framework for the model class instantiation of a package, and implemented a singleton mode, support cross project and group calls, call the format as follows:
D (' [Project://][Group/] model ', ' model layer name ')
The return value of the method is the instantiated model object.
The D method can automatically detect the model class and, if there is a custom model class, instantiate the custom model class and, if it does not, instantiate the model base class and not repeat the instantiated models.
The most common use of the D method is to instantiate a custom model for the current project, for example:
Copy Code code as follows:
Instantiating the user model
$User = D (' User ');
Imports the Lib/model/usermodel.class. File below the current project, and then instantiates the Usermodel class, so the actual code might be equivalent to the following:
Copy Code code as follows:
Import (' @. Model.usermodel ');
$User = new Usermodel ();
However, if the D method is used, if the Usermodel class does not exist, it is automatically invoked
Copy Code code as follows:
And the second call does not need to be instantiated again to reduce the cost of a certain object instantiation.
The D method can support cross grouping and project instantiation models, for example:
Copy Code code as follows:
Instantiate the user model for the admin project
D (' Admin://user ')
Instantiate the user model for the Admin group
D (' Admin/user ')
Note: To implement a cross project invocation model, you must ensure that the directory structure of the two projects is tied.
.1 starts with the addition of layered model support, so the D method can also instantiate other models, such as:
Copy Code code as follows:
Instantiate the UserService class
$User = D (' User ', ' Service ');
Instantiate the Userlogic class
$User = D (' User ', ' Logic ');
Copy Code code as follows:
D (' User ', ' Service ');
Will import Lib/service/userservice.class and instantiate it, which is equivalent to the following code:
Copy Code code as follows:
Import (' @. Service.userservice ');
$User = new Userserivce ();
F method
The F method is actually a subset of the S method, which is used only for simple data caching and only supports file forms, does not support cache expiration, because the return method is used, so its efficiency is higher than s method, so we also call it the fast caching method.
The F method is characterized by:
simple data caching;
File Form Preservation;
Loading the cache using the return data method;
Support for subdirectory caching and automatic creation;
Support for deletion of cache and bulk deletion;
Write and read caching
Copy Code code as follows:
F (' Data ', ' test data ');
The default save Start path is Data_path (the constant is located under Runtime_path. ' data/') in the default configuration, which means that the file named Data_path. ' Data is generated. ' The cached file.
Note: Make sure your cache ID is unique, avoiding data overwrite and conflict.
The next time you read the cached data, use:
Copy Code code as follows:
We can save them in subdirectories, for example:
Copy Code code as follows:
F (' User/data ', $data); Cache Write
F (' User/data '); Read cache
The Data_path. ' User/data. ' Cached file is generated, and if the user subdirectory does not exist, it is created automatically, or it can support multiple levels of subdirectories, for example:
Copy Code code as follows:
F (' Level1/level2/data ', $data);
If you need to specify the cache's starting directory, you can use the following method:
Copy Code code as follows:
F (' Data ', $data, Temp_path);
When you get it, you need to use:
Copy Code code as follows:
F (' Data ', ', ', temp_path);
Delete Cache
Removing the cache is also simple, using:
Copy Code code as follows:
The second parameter, passing in NULL, deletes the data cache that is identified as data.
Support for bulk deletion, especially for subdirectory caching, assuming that we want to delete all cached data below the user subdirectory, you can use:
Copy Code code as follows:
or remove using filter conditions, for example:
Copy Code code as follows:
F (' user/[^a]* ', NULL);
G method
Thinkphp has long been required by the Debug_start, Debug_end method, and even debug classes to complete the function, the 3.1 version by a simple G method replaced, must be called a gorgeous upgrade.
The G method's function includes the mark position and the interval statistic two function, below see the concrete usage:
Mark Position
The first use of the G method is to mark the location, for example:
Copy Code code as follows:
Indicates that the current position is marked as a begin label, and the execution time of the current position is recorded, and memory consumption can be logged if the environment supports it. The G method tag can be invoked at any location.
Run Time statistics
After marking the position, we can call the G method again for interval statistics, for example:
Copy Code code as follows:
G (' begin ');
// ... Other Code Snippets
G (' End ');
// ... Maybe there's another code here.
To perform a statistical interval
echo G (' Begin ', ' end '). S ';
G (' Begin ', ' End ') indicates the execution time (in seconds) of the statistic begin position to the end position, and the beginning must be a marked position, and if the ends are not marked at this time, the current position is automatically marked as the last label, and the output is similar to the following:
Copy Code code as follows:
The default statistic precision is 4 digits after the decimal point, and if you think this statistic is not accurate enough, you can also set up for example:
Copy Code code as follows:
G (' Begin ', ' End ', 6). ' S ';
The possible output becomes:
Copy Code code as follows:
Memory Cost Statistics
If your environment supports memory footprint statistics, you can also use the G method for interval memory cost statistics (in kilobytes), for example:
Copy Code code as follows:
echo G (' Begin ', ' End ', ' m '). KB ';
The third parameter uses m to represent the memory cost statistics, and the output may be:
Copy Code code as follows:
Similarly, if the end tag is not marked, the current position is automatically marked with the first bit of the label.
If the environment does not support memory statistics, the parameter is invalid, and interval running time statistics are still performed.
Forget Debug_start, Debug_end, Boulevard to Jane, you know.
I method
The thinkphp I method is added in the 3.1.3 version, if you are a previous 3.* version, you can refer directly to the variable section of the 3.1 QuickStart tutorial series.
Overview
As you can see, the I method is a new member of many thinkphp functions, named from English input (input), and is used for more convenient and secure access to system input variables, which can be used anywhere, using the following format:
I (' variable type. Variable name ', [' Default value '],[' Filter Method '])
Variable type refers to the type of request or input, including:
Get gets parameter
Post get Post parameters
param automatically determines the request type gets a GET, post, or put parameter
Request GET request parameter
Put to get put parameters
Session get $_session parameter
Cookies get $_cookie Parameters
Server gets $_server parameter
Globals get $GLOBALS parameters
Note: variable types are case-insensitive.
Variable names are strictly case-sensitive.
Both the default value and the filtering method are optional parameters.
Usage
We take the get variable type as an example to illustrate the use of the next I method:
Copy Code code as follows:
echo I (' get.id '); Equivalent to $_get[' ID ']
echo I (' get.name '); Equivalent to $_get[' name ']
Default values are supported:
Copy Code code as follows:
echo I (' Get.id ', 0); Returns 0 if $_get[' id ' is not present
echo I (' get.name ', '); Returns an empty string if $_get[' name ' is not present
Filter by Method:
Copy Code code as follows:
echo I (' get.name ', ', ', ' htmlspecialchars '); Filter $_get[' name ' using the Htmlspecialchars method and return an empty string if not present
Support to get the entire variable type directly, for example:
Copy Code code as follows:
I (' get. '); Get the entire $_get array
In the same way, we can get the post or other input type variables, such as:
Copy Code code as follows:
1.I (' Post.name ', ', ', ' htmlspecialchars '); Filter $_post[' name ' using the Htmlspecialchars method and return an empty string if not present
I (' session.user_id ', 0); Get $_session[' user_id ' if it does not exist, default to 0
I (' cookie. '); Get the entire $_cookie array
I (' Server. Request_method '); Get $_server[' Request_method ']
The Param variable type is a framework-specific support method that automatically determines the type of the current request, such as:
Copy Code code as follows:
If the current request type is get, it is equivalent to get[′id′] and if the current request type is POST or put, it is equivalent to obtaining the _post[' ID ' or the put parameter ID.
and Param type variables can also be indexed to obtain URL parameters (must be valid for PathInfo mode parameters, both get and post methods are valid), for example:
The current Access URL address is
Copy Code code as follows:
Http://serverName/index./New/2013/06/01
Then we can pass
Copy Code code as follows:
echo I (' param.1 '); Output 2013
echo I (' param.2 '); Output 06
echo I (' param.3 '); Output 01
In fact, the Param variable type can be simplified to:
Copy Code code as follows:
I (' id '); Equivalent to I (' param.id ')
I (' name '); Equivalent to I (' Param.name ')
Variable Filter
When using the I method, the variable actually passes through two filters, the first is the global filtering, the global filtering is through the configuration var_filters parameter, here must notice, after 3.1 version, the var_filters parameter filtration mechanism has changed to adopt Array_walk_ Recursive method recursively filtered, the main requirement of filtering method is must reference return, so setting htmlspecialchars here is invalid, you can customize a method, for example:
Copy Code code as follows:
Function Filter_default (& $value) {
$value = Htmlspecialchars ($value);
}
Then configure:
Copy Code code as follows:
' Var_filters ' => ' Filter_default '
If you need to filter multiple times, you can use:
Copy Code code as follows:
' Var_filters ' => ' filter_default,filter_exp '
The Filter_exp method is a built-in security filtering method used to prevent injection attacks using the EXP function of the model.
Because the Var_filters parameter set is the global filtering mechanism, and uses the recursive filtering, has the effect to the efficiency, therefore, we proposed directly to obtain the variable filtering method, in addition to the third parameter of the I method sets the filtering way, also may adopt the configuration Default_ Filter parameter by setting filtering, in fact, the default setting for this parameter is:
Copy Code code as follows:
' Default_filter ' => ' htmlspecialchars '
It is also said that all the acquisition variables of the I method will be htmlspecialchars filtered, then:
Copy Code code as follows:
I (' Get.name '); Equivalent to Htmlspecialchars ($_get[' name ')
Similarly, this parameter can also support multiple filters, such as:
Copy Code code as follows:
' Default_filter ' => ' strip_tags,htmlspecialchars '
Copy Code code as follows:
I (' Get.name '); Equivalent to Htmlspecialchars (strip_tags ($_get[' name '))
If we specify a filtering method when using the I method, the Default_filter settings are ignored, for example:
Copy Code code as follows:
echo I (' get.name ', ', ', ' strip_tags '); Equivalent to Strip_tags ($_get[' name ')
The third parameter of the I method, if passed in the function name, means that the function is invoked to filter the variable and return (automatically use Array_map for filtering when the variable is an array), otherwise the built-in Filter_var method is invoked for filtering, for example:
Copy Code code as follows:
I (' Post.email ', ', ', filter_validate_email);
Indicates that the $_post[' email ' will be formatted for verification, and if it does not meet the requirements, return an empty string.
(For more validation formats, refer to the Filter_var usage of the official manual.) )
Or you can use the following characters to identify the way:
Copy Code code as follows:
I (' Post.email ', ', ', ' email ');
The filter names that can be supported must be valid values in the Filter_list method (different server environments may vary) and may include:
Copy Code code as follows:
Int
Boolean
Float
Validate_regexp
Validate_url
Validate_email
Validate_ip
String
Stripped
Encoded
Special_chars
Unsafe_raw
Email
Url
Number_int
Number_float
Magic_quotes
Callback
In some special cases, we do not want to do any filtering, even if the default_filter has been set up, you can use:
Copy Code code as follows:
I (' Get.name ', ', ', NULL);
Once the filter parameter is set to NULL, it means no more filtering is done.
L method
The L method is used to set and get the current language definition when multilingual is enabled.
Call format: L (' language variable ', [' language value '])
Set Language variables
In addition to using language packs to define language variables, we can use the L method to dynamically set language variables, such as:
Copy Code code as follows:
L (' Lang_var ', ' language definition ');
Language definitions are not case-sensitive, so the following are equivalent:
Copy Code code as follows:
L (' Lang_var ', ' language definition ');
However, for the sake of specification, we recommend unifying uppercase definition language variables.
The L method supports the batch setting of language variables, for example:
Copy Code code as follows:
$lang [' lang_var1 '] = ' language definition 1 ';
$lang [' lang_var2 '] = ' language definition 2 ';
$lang [' lang_var3 '] = ' language definition 3 ';
L ($lang);
Indicates that 3 language variables Lang_var1 lang_var2 and LANG_VAR3 are set at the same time.
[-more-]
Get language variables
Copy Code code as follows:
$langVar = L (' Lang_var ');
Or:
Copy Code code as follows:
$langVar = L (' Lang_var ');
If the argument is empty, it means getting all the currently defined language variables, including those in the language definition file:
Copy Code code as follows:
Or we can use it in a template.
Copy Code code as follows:
To output the language definition.
M method
The M method is used to instantiate an underlying model class, and the D method differs from the following:
, does not need the custom model class, reduces the IO loading, the performance is good;
, and can only invoke the method in the underlying model class (default is the Model class) after instantiation;
, you can specify the table prefix, database and database connection information when instantiating;
The strength of the D method is reflected in the number of custom model classes you encapsulate, but the M method is more and more useful than the D method, as the basic model classes of the new sense framework become more powerful.
Call format for the M method:
M (' [Base model name:] Model name ', ' data table prefix ', ' database connection information ')
Let's take a look at the specific usage of the M method:
, instantiating the underlying model class
In the absence of any model definition, we can instantiate a model class using the following method:
Copy Code code as follows:
Instantiating the user model
$User = M (' User ');
Perform other data operations
$User->select ();
This method is the simplest and most efficient because it does not need to define any model classes, so it supports cross project calls. The disadvantage is that there is no custom model class, so the associated business logic cannot be written, and only basic curd operations can be completed.
Copy Code code as follows:
is actually equivalent to:
Copy Code code as follows:
$User = new Model (' User ');
Represents an Action Think_user table. The M method and the D method also have singleton functions, and multiple invocations are not repeated instantiations. The M method's model name parameter is automatically converted to lowercase when converted to a datasheet, which means that the data table naming specification for the sense is a full lowercase format.
, instantiating other common model classes
The first way to instantiate because there is no definition of a model class, it is difficult to encapsulate some additional logical methods, but in most cases, perhaps just to extend some common logic, you can try one of the following methods.
Copy Code code as follows:
$User = M (' Commonmodel:user ');
The change in usage is actually equivalent to:
Copy Code code as follows:
$User = new Commonmodel (' User ');
Because the system's model classes can be loaded automatically, we do not need to manually perform a class library import before instantiating it. Model class Commonmodel must inherit models. We can define some common logical methods within the Commonmodel class, eliminating the definition of specific model classes for each datasheet, if your project already has more than 100 data tables, and most of the cases are basic curd operations, Only the individual models have some complex business logic that needs to be encapsulated, so the combination of the first and the second is a good choice.
, incoming table prefixes, databases, and other information
The M method has three parameters, the first parameter is the model name (which can include the underlying model class and the database). The second parameter sets the prefix for the data table (left blank to take the table prefix of the current project configuration), and the third parameter is used to set the database connection information that is currently in use (leave the database connection information for the current project configuration blank), For example:
Copy Code code as follows:
$User = M (' DB2. User ', ' think_ ');
Represents the instantiation model class and operates the Think_user table in the DB2 database.
If the second argument is left blank or not, it means that the data table prefix in the current project configuration is used, and if the operation's datasheet does not have a table prefix, you can use:
Copy Code code as follows:
$User = M (' db1. User ', null);
Represents the instantiation model class and operates the user table in the DB1 database.
If you are working in a database that requires a different user account, you can pass in the connection information for the database, for example:
Copy Code code as follows:
$User = M (' User ', ' think_ ', ' mysql://user_a:1234@localhost:3306/think ');
The basic model class is modeled, then the Think_user table is operated, the database is connected with the User_a account, and the Operation database is.
The third connection information parameter can be used with DSN configuration or array configuration, or even configuration parameters can be supported.
For example, in a project configuration file, you configure:
Copy Code code as follows:
' Db_config ' => ' mysql://user_a:1234@localhost:3306/think ';
You can use the following:
Copy Code code as follows:
$User = M (' User ', ' think_ ', ' db_config ');
The underlying model classes and databases can be used together, for example:
Copy Code code as follows:
$User = M (' Commonmodel:db2. User ', ' think_ ');
If you want to instantiate a layered model, using the common model class, we can use:
Copy Code code as follows:
To instantiate the Userlogic, although this does not make sense because you can use the
Copy Code code as follows:
Achieve the same function.
R method
The R method is used to invoke the operation method of a controller, and is further enhanced and supplemented by a method. See here for the usage of a method.
Call format for the R method:
R (' [item://][Grouping/] Module/operation ', ' parameter ', ' Controller layer name ')
For example, we define an action method that is:
Copy Code code as follows:
Class Useraction extends Action {
Public Function Detail ($id) {
Return M (' User ')->find ($id);
}
}
Then you can call this action method in other controllers by using the R method (the general R method is used to call across modules)
Copy Code code as follows:
$data = R (' User/detail ', Array (' 5 '));
Represents the detail method that invokes the user controller (the detail method must be a public type), and the return value is a user data with Query ID 5. If you want to invoke an action method that has no arguments, the second argument can be left blank and used directly:
Copy Code code as follows:
$data = R (' User/detail ');
You can also support cross grouping and project calls, such as:
Copy Code code as follows:
R (' Admin/user/detail ', Array (' 5 '));
Represents the detail method that invokes the user controller under the Admin group.
Copy Code code as follows:
R (' Admin://user/detail ', Array (' 5 '));
Represents the detail method that invokes the user controller under the Admin project.
The official advice is not to make too many calls on the same floor, which can cause logical confusion, the part of the public call should be encapsulated into a separate interface that can be used to add a single controller layer to the interface call by using 3.1 of the new feature multilayer controllers, for example, we add an API controller layer,
Copy Code code as follows:
Class Userapi extends Action {
Public Function Detail ($id) {
Return M (' User ')->find ($id);
}
}
Then, use the R method to call the
Copy Code code as follows:
$data = R (' User/detail ', Array (' 5 '), ' Api ');
In other words, the third parameter of the R method supports the controller layer that specifies the call.
Also, the R method invokes the action method to support the operation suffix setting C (' Action_suffix '), and if you set the action method suffix, you still do not need to change the way the R method is invoked.
S method
The S method also supports passing in cache parameters to the current caching method, for example:
Copy Code code as follows:
S (' Data ', $Data, 3600, ' File ', array (' Length ' =>10, ' temp ' =>runtime_path. ' temp/'));
After testing, this use only the first three parameters are valid, the following are invalid
Copy Code code as follows:
{' File ', array (' Length ' =>10, ' temp ' =>runtime_path ' temp/')}
In the end:
Copy Code code as follows:
S (' data1 ', $list, array (' prefix ' =>aaa ', ' expire ' => ' 3600 ', ' temp ' =>runtime_path. ' temp/1236 '));
Time to get:
Copy Code code as follows:
$sdata = S (' data1 ', ', ', array (' prefix ' => ' aaa ', ' temp ' =>runtime_path. ' temp/1236 '));
T method
For a more convenient output template file, the new version encapsulates a T function to generate the template file name.
Usage:
T ([Resource://][module @][Theme/][Controller/] operation, [view hierarchy])
The return value of the T function is a complete template file name that can be used directly for display and fetch methods for rendering output.
For example:
Copy Code code as follows:
T (' Public/menu ');
Returns the current module/view/public/menu.html
T (' Blue/public/menu ');
Returns the current module/view/blue/public/menu.html
T (' Public/menu ', ' Tpl ');
Returns the current module/tpl/public/menu.html
T (' Public/menu ');
If Tmpl_file_depr to _ returns the current module/tpl/public_menu.html
T (' Public/menu ');
If Tmpl_template_suffix returns the current module as. TPL/TPL/PUBLIC/MENU.TPL
T (' Admin@public/menu ');
Back to Admin/view/public/menu.html
T (' Extend://admin@public/menu ');
Returns extend/admin/view/public/menu.html (Extend directory depends on configuration in autoload_namespace)
Use the T function directly in the display method:
Copy Code code as follows:
Output template using T function
$this->display (T (' Admin@public/menu '));
The T function can output different view hierarchy templates.
U method
The U method is used to assemble the URL address, which is characterized in that it can automatically generate the corresponding URL address based on the current URL pattern and settings:
U (' address ', ' parameter ', ' pseudo static ', ' Jump ', ' Show domain name ');
The advantage of using the U method in a template instead of fixing a dead URL address is that you don't need to change any of the code in the template once your environment changes or the parameter settings change.
The calling format in the template needs to be in the way of {: U (' address ', ' parameter ' ...)}
Examples of the use of the U method:
Copy Code code as follows:
U (' user/add ')//Generate add Operation address for User module
You can also support group calls:
Copy Code code as follows:
U (' home/user/add ')//Generate add Operation address of User module for home grouping
Of course, you can just write the name of the operation, which means the call to the current module
Copy Code code as follows:
U (' add ')//Generate add operation address for current access module
In addition to grouping, module, and operation names, we can pass in some parameters:
Copy Code code as follows:
U (' blog/readid=1 ')//generate the read operation of the Blog module and URL address with ID 1
The second parameter of the U method supports the passed-in arguments, supports both arrays and strings, and is equivalent if only the parameters of the string method can be defined in the first argument:
Copy Code code as follows:
U (' blog/cate ', Array (' cate_id ' =>1, ' status ' =>1))
U (' blog/cate ', ' Cate_id=1&status=1 ')
U (' Blog/catecate_id=1&status=1 ')
However, the following definition is not allowed to be used to pass parameters:
Copy Code code as follows:
U (' BLOG/CATE/CATE_ID/1/STATUS/1 ')
Depending on the URL settings of the project, the same U-method invocation can intelligently correspond to different URL-address effects, for example:
Copy Code code as follows:
This definition is an example.
If the current URL is set to normal mode, the last generated URL address is:
Copy Code code as follows:
Http://serverName/index.m=Blog&a=read&id=1
If the current URL is set to PathInfo mode, the same method finally generates the URL address: HTTP://SERVERNAME/INDEX./BLOG/READ/ID/1
If the current URL is set to rewrite mode, the same method finally generates the URL address: HTTP://SERVERNAME/BLOG/READ/ID/1
If you also set the PathInfo separator:
Copy Code code as follows:
' Url_pathinfo_depr ' => ' _ '
will be generated
Copy Code code as follows:
Http://serverName/Blog_read_id_1
If the current URL is set to rewrite mode and the pseudo static suffix is set to HTML, the same method finally generates the URL address:
Copy Code code as follows:
Http://serverName/Blog/read/id/1.html
If multiple pseudo static support is set, the first pseudo static suffix is automatically added to the URL address, but you can also manually specify the pseudo static suffix to be generated in the U method, for example:
Copy Code code as follows:
U (' Blog/read ', ' id=1 ', ' xml ')
will be generated
Copy Code code as follows:
Http://serverName/Blog/read/id/1.xml
The U method can also support routing if we define a routing rule that is:
Copy Code code as follows:
' news/:id\d ' => ' news/read '
Then you can use
Copy Code code as follows:
The resulting URL address is:
Copy Code code as follows:
Http://serverName/index./news/1
If your application involves multiple subdomains, you can also specify the domain name in the U method that requires the address to be generated, for example:
Copy Code code as follows:
U (' blog/read@blog.think.cn ', ' id=1 ');
@ then pass in the domain name you want to specify.
In addition, the 5th parameter of the U method, if set to true, indicates that the current domain name is automatically recognized and automatically matches the App_sub_domain_deploy and app_sub_domain_rules that generate the current address based on the child domain name deployment settings.
If Url_case_insensitive is turned on, a lowercase URL address is generated uniformly.