thinkphpÔõôÌá½»Êý¾Ý
ʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢£¬Ìá½»Êý¾ÝÊǷǾ³£¼ûµÄ²Ù×÷¡£Ôڸÿò¼ÜÖУ¬Ìá½»Êý¾ÝµÄ·½·¨ÓжàÖÖ£¬ÏêϸÈçÏ£º
1. GET·½·¨Ìá½»Êý¾Ý
ʹÓÃGET·½·¨Ìá½»Êý¾Ý£¬¿ÉÒÔͨ¹ýURLµØµãת´ï²ÎÊý£¬¸Ã·½·¨ÊÊÓÃÓÚÉÙÁ¿µÄÊý¾Ý£¬ºÃ±ÈËÑË÷Òªº¦×Ö¡¢·ÖÒ³µÈ²Ù×÷¡£ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡GET²ÎÊý£º
// »ñÈ¡µ¥¸öGET²ÎÊý $param = input('get.param'); // »ñÈ¡ËùÓÐGET²ÎÊý $params = input('get.');
µÇ¼ºó¸´ÖÆ
2. POST·½·¨Ìá½»Êý¾Ý
ʹÓÃPOST·½·¨Ìá½»Êý¾Ý£¬¿ÉÒÔÏòЧÀÍÆ÷·¢ËÍ´ó×ÚÊý¾Ý£¬ºÃ±È±íµ¥Êý¾Ý¡¢ÎļþÉÏ´«µÈ¡£ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡POST²ÎÊý£º
// »ñÈ¡µ¥¸öPOST²ÎÊý $param = input('post.param'); // »ñÈ¡ËùÓÐPOST²ÎÊý $params = input('post.');
µÇ¼ºó¸´ÖÆ
3. JSON·½·¨Ìá½»Êý¾Ý
ʹÓÃJSON·½·¨Ìá½»Êý¾Ý£¬¿ÉÒÔÔÚÇ°ºó¶ËÊèÉ¢µÄ¿ª·¢ÖÐʹÓã¬Í¨¹ýAJAXµÈ·½·¨½«JSONÊý¾ÝÃûÌ÷¢Ë͵½Ð§ÀÍÆ÷¶Ë¡£ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡JSON²ÎÊý£º
// »ñÈ¡JSON²ÎÊý $json = file_get_contents('php://input'); $params = json_decode($json, true); // ½«JSON×Ö·û´®×ª»»³ÉÊý×é
µÇ¼ºó¸´ÖÆ
4. PUT·½·¨Ìá½»Êý¾Ý
ʹÓÃPUT·½·¨Ìá½»Êý¾Ý£¬¿ÉÒÔ¶ÔЧÀÍÆ÷ÉÏÒÑÓÐ×ÊÔ´¾ÙÐÐÐ޸ġ£ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡PUT²ÎÊý£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
// »ñÈ¡PUT²ÎÊý $put = file_get_contents("php://input"); parse_str($put, $params); // ½«PUT²ÎÊýת»»³ÉÊý×é
µÇ¼ºó¸´ÖÆ
5. DELETE·½·¨Ìá½»Êý¾Ý
ʹÓÃDELETE·½·¨Ìá½»Êý¾Ý£¬¿ÉÒÔɾ³ýЧÀÍÆ÷ÉÏÒÑÓÐ×ÊÔ´¡£ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨»ñÈ¡DELETE²ÎÊý£º
// »ñÈ¡DELETE²ÎÊý $delete = $_SERVER['QUERY_STRING']; parse_str($delete, $params); // ½«DELETE²ÎÊýת»»³ÉÊý×é
µÇ¼ºó¸´ÖÆ
³ýÁËÒÔÉÏ5ÖÖ·½·¨£¬ThinkPHP¿ò¼Ü»¹ÌṩÁËinput¹¤¾ß£¬¿ÉÒÔͨ¹ýÈçÏ·½·¨»ñÈ¡Ìá½»µÄÊý¾Ý£º
// »ñÈ¡All²ÎÊý£¨°üÀ¨GET¡¢POST¡¢JSON¡¢PUT¡¢DELETE£© $params = input('param.');
µÇ¼ºó¸´ÖÆ
ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔƾ֤×Ô¼ºÏÖʵÐèÇóÑ¡ÔñºÏÊʵķ½·¨»ñÈ¡Ìá½»µÄÊý¾Ý¡£Í¬Ê±£¬ÐèҪעÖØÇå¾²ÐÔ£¬¹ØÓÚÓû§Ìá½»µÄÊý¾ÝÐèÒª¾ÙÐйýÂ˺ÍÑéÖ¤£¬±ÜÃâ×¢ÈëºÍ¹¥»÷µÈ¶ñÒâÐÐΪ¡£
ÒÔÉϾÍÊÇthinkphpÔõôÌá½»Êý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡