About the U method
This post was last edited by lmq_2016 on 2015-05-04 22:57:34
Let's start with the question: when you see someone else using the U method in thinkphp, you use U (' verify ')
Where parameter verify is a custom method in a controller
So the question is, why is this form of invocation effective, and here's how you approach it, and you don't see where you can use it?
function U ($url, $vars = ", $suffix =true, $redirect =false, $domain =false) {
Parsing URLs
$info = Parse_url ($url);
$url =!empty ($info [' path '])? $info [' Path ']:action_name;
Resolving sub-domains
if ($domain ===true) {
$domain = $_server[' http_host ');
if (C (' App_sub_domain_deploy ')) {//Enable sub-domain deployment
$domain = $domain = = ' localhost '? localhost ': ' www '. Strstr ($_server[' http_host '), '. ');
' Sub domain ' =>array (' project [/Group] ');
foreach (C (' App_sub_domain_rules ') as $key = = $rule) {
if (false = = = Strpos ($key, ' * ') && 0=== strpos ($url, $rule [0])) {
$domain = $key. Strstr ($domain, '. '); Generate the corresponding sub-domain name
$url = Substr_replace ($url, "', 0,strlen ($rule [0]));
Break
}
}
}
}
Parsing parameters
if (is_string ($vars)) {//aaa=1&bbb=2 convert an array
Parse_str ($vars, $vars);
}elseif (!is_array ($vars)) {
$vars = Array ();
}
if (Isset ($info [' query '])) {//resolve address inside parameters merged into VARs
Parse_str ($info [' query '], $params);
$vars = Array_merge ($params, $vars);
}
URL Assembly
$depr = C (' Url_pathinfo_depr ');
if ($url) {
if (0=== strpos ($url, '/')) {//define route
$route = true;
$url = substr ($url, 1);
if ('/'! = $depr) {
$url = Str_replace ('/', $depr, $url);
}
}else{
if ('/'! = $DEPR) {//safe replace
$url = Str_replace ('/', $depr, $url);
}
parsing groupings, modules, and operations
$url = Trim ($url, $DEPR);
$path = Explode ($depr, $url);
$var = Array ();
$var [C (' var_action ')] =!empty ($path)? Array_pop ($path): Action_name;
$var [C (' var_module ')] =!empty ($path)? Array_pop ($path): module_name;
if (C (' url_case_insensitive ')) {
$var [C (' var_module ')] = Parse_name ($var [C (' Var_module ')]);
}
if (C (' app_group_list ')) {
if (!empty ($path)) {
$group = Array_pop ($path);
$var [C (' var_group ')] = $group;
}else{
if (group_name! = C (' Default_group ')) {
$var [C (' var_group ')] = group_name;
}
}
}
}
}
if (C (' url_model ') = = 0) {//Normal mode URL translation
$url = __app__. '? '. Http_build_query ($var);
if (!empty ($vars)) {
$vars = Http_build_query ($vars);
$url. = ' & '. $vars;
}
}else{//pathinfo mode or compatible URL mode
if (Isset ($route)) {
$url = __app__. ' /'. $url;
}else{
$url = __app__. ' /'. Implode ($depr, Array_reverse ($var));
}
if (!empty ($vars)) {//Add parameter
$vars = Http_build_query ($vars);
$url. = $depr. Str_replace (Array (' = ', ' & '), $depr, $vars);
}
if ($suffix) {
$suffix = $suffix ===true? C (' Url_html_suffix '): $suffix;
if ($suffix) {
$url. = '. '. LTrim ($suffix, '. ');
}
}
}
if ($domain) {
$url = ' http://' $domain. $url;
}
if ($redirect)//Direct Jump URL
Redirect ($url);
Else
return $url;
}
URL redirection
------to solve the idea----------------------
$url = ' verify ';
$info = Parse_url ($url);
Array
(
[Path] = Verify
)
You'll know when you follow me.