thinkphp5ÔõÑù»ñÈ¡ÇëÇó¹ýÀ´µÄÍøÖ·
thinkphp5»ñÈ¡ÇëÇóÍøÖ·µÄÒªÁ죺1¡¢Ê¹Óá°\think\Request¡±ÀàµÄ¡°$request = Request::instance();¡±ÒªÁì»ñÈ¡Ä¿½ñµÄurlÐÅÏ¢£»2¡¢Í¨¹ý×Ô´øµÄÖúÊÖº¯Êý¡°$request->url()¡±»ñÈ¡°üÀ¨ÓòÃûµÄÍêÕûURLµØµã¡£
THINKPHP5»ñÈ¡Ä¿½ñÒ³ÃæURLÐÅÏ¢
ÏëÒª»ñÈ¡Ä¿½ñÒ³ÃæµÄurlÐÅÏ¢£¬¿ÉÒÔ½èÖúthinkphp ×Ô´øµÄrequest ÀàÀ´»ñÈ¡Ä¿½ñµÄurlÐÅÏ¢
ʹÓÃ\think\RequestÀà
$request = Request::instance();<br>
µÇ¼ºó¸´ÖÆ
»òÕßʹÓÃ×Ô´øµÄÖúÊÖº¯Êý
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
$request = request();<br>
µÇ¼ºó¸´ÖÆ
$request = Request::instance(); // »ñÈ¡Ä¿½ñÓòÃû echo 'domain: ' . $request->domain() . '<br/>'; // »ñÈ¡Ä¿½ñÈë¿ÚÎļþ echo 'file: ' . $request->baseFile() . '<br/>'; // »ñÈ¡Ä¿½ñURLµØµã ²»º¬ÓòÃû echo 'url: ' . $request->url() . '<br/>'; // »ñÈ¡°üÀ¨ÓòÃûµÄÍêÕûURLµØµã echo 'url with domain: ' . $request->url(true) . '<br/>'; // »ñÈ¡Ä¿½ñURLµØµã ²»º¬QUERY_STRING echo 'url without query: ' . $request->baseUrl() . '<br/>'; // »ñÈ¡URL»á¼ûµÄROOTµØµã echo 'root:' . $request->root() . '<br/>'; // »ñÈ¡URL»á¼ûµÄROOTµØµã echo 'root with domain: ' . $request->root(true) . '<br/>'; // »ñÈ¡URLµØµãÖеÄPATH_INFOÐÅÏ¢ echo 'pathinfo: ' . $request->pathinfo() . '<br/>'; // »ñÈ¡URLµØµãÖеÄPATH_INFOÐÅÏ¢ ²»º¬ºó׺ echo 'pathinfo: ' . $request->path() . '<br/>'; // »ñÈ¡URLµØµãÖеĺó׺ÐÅÏ¢ echo 'ext: ' . $request->ext() . '<br/>';
µÇ¼ºó¸´ÖÆ
Êä³öЧ¹û
domain: https://luweipai.cn<br/>file: /index.php<br/>url: /index/index/hello.html?name=luweipai<br/>url with domain: https://luweipai.cn/index/index/hello.html?name=luweipai<br/>url without query: /index/index/hello.html<br/>root:<br/>root with domain: http://luweipai.cn<br/>pathinfo: index/index/hello.html<br/>pathinfo: index/index/hello<br/>ext: html
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇthinkphp5ÔõÑù»ñÈ¡ÇëÇó¹ýÀ´µÄÍøÖ·µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡
ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£