thinkphpÔõôÅжÏÇëÇó·½·¨
thinkphpÊÇÒ»¸öÓÅÒìµÄphp¿ò¼Ü£¬ËüÌṩÁ˸»ºñµÄº¯ÊýºÍÒªÁìÀ´×ÊÖú¿ª·¢ÕßʵÏÖÖÖÖÖ¹¦Ð§¡£ÆäÖУ¬ÅжÏÇëÇó·½·¨ÊÇweb¿ª·¢ÖзǾ³£¼ûµÄ¹¦Ð§Ö®Ò»¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃthinkphpÀ´ÅжÏhttpÇëÇó·½·¨¡£
HTTPÇëÇó·½·¨¸ÅÊö
ÔÚHTTPÐÒéÖУ¬ÇëÇó·½·¨£¨Request Method£©´ú±í¿Í»§¶Ë£¨Í¨³£ÊÇWebä¯ÀÀÆ÷£©Ï£ÍûЧÀÍÆ÷Ö´ÐеÄÐж¯¡£HTTPÐÒéÏÖÔÚ½ç˵ÁË8ÖÖÇëÇó·½·¨£¬»®·ÖÊÇ£º
GET£ºÏòЧÀÍÆ÷ÇëÇóÒ»¸ö×ÊÔ´£¬Ð§ÀÍÆ÷·µ»Ø¸Ã×ÊÔ´£»
POST£ºÌá½»Êý¾Ýµ½Ð§ÀÍÆ÷£¬Ð§ÀÍÆ÷´¦Öóͷ£¸ÃÊý¾Ý£»
PUT£º¸üÐÂЧÀÍÆ÷ÉϵÄ×ÊÔ´£»
DELETE£ºÉ¾³ýЧÀÍÆ÷ÉϵÄ×ÊÔ´£»
HEAD£º»ñȡЧÀÍÆ÷¶Ô×ÊÔ´µÄÏìӦͷÐÅÏ¢£¬¶ø²»·µ»Ø×ÊÔ´µÄʵÌåÄÚÈÝ£»
OPTIONS£ºÅÌÎÊЧÀÍÆ÷Õë¶Ô×ÊÔ´Ö§³ÖµÄÇëÇó·½·¨£»
CONNECT£º½¨ÉèÍøÂçÅþÁ¬ËíµÀ£¬ÓÃÓÚÊðÀíЧÀÍÆ÷£»
TRACE£º×·×ÙЧÀÍÆ÷Ö®¼äµÄͨѶ·¾¶¡£
ÆäÖУ¬GETºÍPOSTÇëÇó·½·¨ÊÇ×î³£Óõġ£
ThinkPHPÖÐÅжÏÇëÇó·½·¨µÄÒªÁì
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHP¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃRequest¹¤¾ßÌṩµÄÒªÁìÀ´ÅжÏÄ¿½ñµÄHTTPÇëÇó·½·¨¡£Request¹¤¾ßÊÇϵͳ¼¶±ðµÄÀ࣬ÎÒÃÇ¿ÉÒÔͨ¹ýŲÓøù¤¾ßÌṩµÄÒªÁìÀ´²Ù×÷Ä¿½ñHTTPÇëÇó¡£ÒÔÏÂÊÇһЩ³£ÓõÄÅжÏHTTPÇëÇó·½·¨µÄÒªÁ죺
isPost()
¸ÃÒªÁìÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñΪPOSTÇëÇó¡£ÈôÊÇÄ¿½ñÇëÇóÊÇPOSTÇëÇó£¬Ôò·µ»Øtrue£¬²»È»·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; if (Request::isPost()) { // do something... }
µÇ¼ºó¸´ÖÆ
isGet()
¸ÃÒªÁìÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñΪGETÇëÇó¡£ÈôÊÇÄ¿½ñÇëÇóÊÇGETÇëÇó£¬Ôò·µ»Øtrue£¬²»È»·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; if (Request::isGet()) { // do something... }
µÇ¼ºó¸´ÖÆ
isPut()
¸ÃÒªÁìÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñΪPUTÇëÇó¡£ÈôÊÇÄ¿½ñÇëÇóÊÇPUTÇëÇó£¬Ôò·µ»Øtrue£¬²»È»·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; if (Request::isPut()) { // do something... }
µÇ¼ºó¸´ÖÆ
isDelete()
¸ÃÒªÁìÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñΪDELETEÇëÇó¡£ÈôÊÇÄ¿½ñÇëÇóÊÇDELETEÇëÇó£¬Ôò·µ»Øtrue£¬²»È»·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; if (Request::isDelete()) { // do something... }
µÇ¼ºó¸´ÖÆ
isAjax()
¸ÃÒªÁìÓÃÓÚÅжÏÄ¿½ñÇëÇóÊÇ·ñΪAjaxÇëÇó¡£ÈôÊÇÄ¿½ñÇëÇóÊÇAjaxÇëÇó£¬Ôò·µ»Øtrue£¬²»È»·µ»Øfalse¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; if (Request::isAjax()) { // do something... }
µÇ¼ºó¸´ÖÆ
method()
¸ÃÒªÁìÓÃÓÚ»ñÈ¡Ä¿½ñµÄHTTPÇëÇó·½·¨¡£ÒªÁì·µ»ØµÄЧ¹ûȫΪ´óд×Öĸ¡£Ê¾Àý´úÂëÈçÏ£º
use think\facade\Request; $method = Request::method(); if ($method == 'GET') { // do something... } elseif ($method == 'POST') { // do something... }
µÇ¼ºó¸´ÖÆ
×ÛÉÏËùÊö£¬ÎÒÃÇÔÚʹÓÃThinkPHP¿ª·¢Ê±£¬¿ÉÒÔʹÓÃRequest¹¤¾ßÌṩµÄÒªÁìÇáËÉÅжÏÄ¿½ñÇëÇóµÄHTTPÇëÇó·½·¨£¬²¢Æ¾Ö¤ÅжÏЧ¹ûÖ´Ðвî±ðµÄÓªÒµÂß¼¡£
ÒÔÉϾÍÊÇthinkphpÔõôÅжÏÇëÇó·½·¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡