ZPF Routing Capabilities

Source: Internet
Author: User
Tags subdomain

2015-4-11 20:51:06

Another day, solved a bunch of bugs, re-planning the class folder, improve the automatic loading function

The newest feature is the support for sub-domain routing

Because the whole framework is still being perfected, and there are a lot of interfaces with my own application of the third party Appkey and Secretkey, so it is not convenient to provide download

But after the completion of the routing function, the whole framework is almost finished, and then the tinkering is done.

Four years, from the beginning of the zero, finally have a model of a kind of ....

Like what:

Visit www.zhangzhibin.com will jump to the homepage of the website

Visit Www.zhangzhibin.com/bbs is going to jump to BBS forum page

But I want to go to BBS forum page when I visit love.zhangzhibin.com (because the developer information left by the Volkswagen reviews is love.zhangzhibin.com)

You can set a corresponding relationship in the routing file (line 8th):

1  Public functionSetroute ()2     {3         $this->route_config =Array(4' Subdomain ' =Array(),5' uri ' = =Array());6 7         //================ sub-domain Routing8         $this->route_config[' subdomain ' [' #love # '] = ' bbs/index/index ';9         //================ URI RoutingTen         $this->route_config[' uri ' [' # ([a-z]+] _ (\d+) \.html# '] = ' test/index/testroute/$1/$2 '; One         $this->route_config[' URI ' [' #map \.html# '] = ' map/index/line '; A}

Note that there are two ' # ' on both sides of the key of the route entry as the bounding characters need to write their own, if you are concerned about the conflict, you can set the boundary character on your own.

The logic of the whole is this.

Match the route of the sub-domain name first, and then match the route of the URI (mismatch? query string behind)

Combine the two-step matching parameters, because the URI matches the second step, so the matching result of the URI overwrites the sub-domain's routing result

Paste the code below: (The time to jump out of the loop is still to be optimized ...)

1<?PHP2 classRoute3 {4      Public $routename= ' ';5 6      Public $route _config=Array();7 8      Public $ismatch=false;9 Ten      Public $module= ' '; One      Public $controller= ' '; A      Public $action= ' '; -  -      Public $args=Array(); the  -      Public $subdomain= ' '; -      Public $uri= ' '; -  +      Public $error= ' '; -  +      Public function__construct ($subdomain,$uri) A     { at         $this->subdomain =$subdomain; -         $this->uri =$uri; -  -         //Set up routing configuration information -         $this-Setroute (); -  in         //Check sub-domain Routing first -         $this-Parse_subdomain (); to  +         //Check URI routing again -         $this-Parse_uri (); the  *         return $this; $     }Panax Notoginseng  -      Public functionSetroute () the     { +         $this->route_config =Array( A' Subdomain ' =Array(), the' uri ' = =Array()); +  -         //================ sub-domain Routing $         $this->route_config[' subdomain ' [' #love # '] = ' bbs/index/index '; $         //================ URI Routing -         $this->route_config[' uri ' [' # ([a-z]+] _ (\d+) \.html# '] = ' test/index/testroute/$1/$2 '; -         $this->route_config[' URI ' [' #map \.html# '] = ' map/index/line '; the     } - Wuyi      Public functionParse_subdomain () the     { -         $this->subdomain &&$this->parse ($this->route_config[' subdomain '),$this-subdomain); Wu     } -  About      Public functionParse_uri () $     { -         $this->uri &&$this->parse ($this->route_config[' URI '],$this-URI); -     } -  A      Public functionParse$routeconfig,$subject) +     { the         foreach($routeconfig  as $pattern=$route) { -             $arrRoute=Explode(‘/‘,$route); $              the             //if (count ($arrRoute) < 3) { the //$this->error = $pattern. ': module/controller/action/$1/$2 not specified ... '; the             // } the              - //Preg_match_all ($pattern, $uri, $matches); in             Preg_match($pattern,$subject,$matches); the  the             if(Empty($matches)) { About                 Continue; the}Else { the                 $arrMCA=Array_slice($arrRoute, 0, 3); the                 $arrArg=Array_slice($arrRoute, 3); +  -                 $this->routename =$pattern; the Bayi                 $this->module =$arrMCA[0]; the                 $this->controller =$arrMCA[1]; the                 $this->action =$arrMCA[2]; -  -                 $arrMatchArg=Array(); the                 foreach($matches  as $key=$value) { the                     $arrMatchArg[' $ '.$key] =$value; the                 } the  -                 foreach($arrArg  as $value) { the                     $this->args[$value] =$arrMatchArg[$value]; the                 } the 94                 $this->ismatch =true; the                  Break; the             } the         }98     } About}

ZPF Routing Capabilities

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: info-contact@alibabacloud.com 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.