thinkphpÇëÇó´ø²ÎµÄÒªÁì
ÔÚweb¿ª·¢ÖУ¬¾³£»áÓöµ½ÐèÒªÒÔÇ°¶ËÒ³ÃæÏòºó¶ËЧÀÍÆ÷·¢ËÍ´ø²ÎÊýµÄÇëÇ󡣶øÔÚphp¿ò¼ÜÖУ¬thinkphpÊÇÒ»¸öºÜÊÇÓÅÒìµÄÑ¡Ôñ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp¿ò¼ÜÖз¢ËÍ´ø²ÎÊýÇëÇóµÄÒªÁì¡£
thinkphp¿ò¼ÜÌṩÁ˶àÖÖÒªÁìÀ´·¢ËÍÇëÇó£¬×î³£¼ûµÄÊÇʹÓÃcurl¿â·¢ËÍHTTPÇëÇ󡣿ÉÊÇ£¬ÕâÖÖÒªÁìÐèҪдһЩÏà¶Ô½Ï¶àµÄ´úÂ룬ÐèÒªÉèÖÃÐí¶à²ÎÊý£¬²»Ì«ÓѺá£Í¬Ê±£¬thinkphp¿ò¼Ü»¹ÌṩÁ˸üΪ¼òÆӵķ½·¨£¬¿ÉÒÔͨ¹ý×Ô´øµÄRequest¹¤¾ßÀ´·¢ËÍÇëÇó¡£
getÒªÁì
getÒªÁì³£ÓÃÓÚ´ÓЧÀÍÆ÷»ñÈ¡Êý¾Ý£¬Í¨¹ýURLת´ï²ÎÊý¡£ÎÒÃÇ¿ÉÒÔʹÓÃRequest¹¤¾ßµÄparamÒªÁì»ñÈ¡GET²ÎÊý£¬Ê¾ÀýÈçÏ£º
use thinkRequest; $request = Request::instance(); $id = $request->param('id'); $name = $request->param('name');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃuseÒªº¦×ÖÒýÈëRequestÀ࣬Ȼºóͨ¹ýRequest::instance()ÒªÁì»ñÈ¡Request¹¤¾ß¡£½ÓÏÂÀ´£¬ÎÒÃÇ¿ÉÒÔʹÓÃparamÒªÁìÀ´»ñÈ¡URLת´ïµÄ²ÎÊý¡£ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒª»ñÈ¡idºÍname²ÎÊý£¬¿ÉÒÔÏñÉÏÃæʾÀýÖÐÄÇÑùд´úÂë¡£
postÒªÁì
postÒªÁìͨ³£ÓÃÓÚÏòЧÀÍÆ÷Ìá½»Êý¾Ý£¬Í¨¹ý±íµ¥µÈ·½·¨×ª´ï²ÎÊý¡£ÎÒÃÇ¿ÉÒÔͨ¹ýRequest¹¤¾ßµÄpostÒªÁì»ñÈ¡POST²ÎÊý£¬Ê¾ÀýÈçÏ£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
use thinkRequest; $request = Request::instance(); $username = $request->post('username'); $password = $request->post('password');
µÇ¼ºó¸´ÖÆ
ÓëgetÒªÁìÀàËÆ£¬ÉÏÊö´úÂëÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃuseÒªº¦×ÖÒýÈëRequestÀ࣬Ȼºóͨ¹ýRequest::instance()ÒªÁì»ñÈ¡Request¹¤¾ß¡£½Ó×Å£¬ÎÒÃÇ¿ÉÒÔʹÓÃpostÒªÁìÀ´»ñÈ¡POST²ÎÊý¡£ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒª»ñÈ¡Óû§ÃûºÍÃÜÂë²ÎÊý£¬¿ÉÒÔÏñÉÏÃæʾÀýÖÐÄÇÑùд´úÂë¡£
requestÒªÁì
requestÒªÁìÊÇÒ»¸ö½ÏÁ¿Í¨ÓõÄÒªÁ죬¿ÉÒÔͬʱ»ñÈ¡GETºÍPOST²ÎÊý¡£ÎÒÃÇ¿ÉÒÔͨ¹ýRequest¹¤¾ßµÄrequestÒªÁì»ñÈ¡ÇëÇó²ÎÊý£¬ÀýÈ磺
use thinkRequest; $request = Request::instance(); $name = $request->request('name'); $age = $request->request('age');
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇÊ×ÏÈʹÓÃuseÒªº¦×ÖÒýÈëRequestÀ࣬Ȼºóͨ¹ýRequest::instance()ÒªÁì»ñÈ¡Request¹¤¾ß¡£½Ó×Å£¬ÎÒÃÇ¿ÉÒÔʹÓÃrequestÒªÁìÀ´»ñÈ¡ÇëÇó²ÎÊý¡£ÀýÈ磬ÈôÊÇÎÒÃÇÐèÒª»ñÈ¡Óû§ÃûºÍÄêËê²ÎÊý£¬¿ÉÒÔÏñÉÏÃæʾÀýÖÐÄÇÑùд´úÂë¡£
´øĬÈÏÖµµÄ»ñÈ¡·½·¨
ÈôÊÇÎÒÃÇÏëÔÚûÓÐת´ï²ÎÊýʱÉèÖÃÒ»¸öĬÈÏÖµ£¬¿ÉÒÔÔÚparam¡¢post»òrequestÒªÁìµÄµÚ¶þ¸ö²ÎÊýÖÐÉèÖã¬Ä¬ÈÏÖµ¡£ÀýÈ磺
use thinkRequest; $request = Request::instance(); $id = $request->param('id', 0); // ÈôÊÇûÓÐת´ï'id'²ÎÊý£¬ÔòĬÈÏֵΪ0 $name = $request->param('name', 'unknown'); // ÈôÊÇûÓÐת´ï'name'²ÎÊý£¬ÔòĬÈÏֵΪ'unknown'
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇÔÚparamÒªÁìµÄµÚ¶þ¸ö²ÎÊýÖÐÉèÖÃÁËĬÈÏÖµ¡£ÈôÊÇûÓÐת´ï²ÎÊý£¬½«»á·µ»ØÎÒÃÇÉèÖõÄĬÈÏÖµ¡£
¶à¸ö²ÎÊý»ñÈ¡·½·¨
µ±ÎÒÃÇÐèÒª»ñÈ¡¶à¸ö²ÎÊýʱ£¬¿ÉÒÔʹÓÃparamÒªÁìת´ïÒ»¸ö°üÀ¨ËùÓвÎÊýÃûµÄÊý×é¡£ÀýÈ磺
use thinkRequest; $request = Request::instance(); $params = $request->param(['id', 'name', 'age']);
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃparamÒªÁìת´ïÁËÒ»¸ö°üÀ¨’id’¡¢’name’ºÍ’age’²ÎÊýÃûµÄÊý×飬½«»á·µ»Ø°üÀ¨ÕâЩ²ÎÊýµÄ¹ØÁªÊý×é¡£
»ñÈ¡ÇëÇóÒªÁì
ÔÚijЩÇéÐÎÏ£¬ÎÒÃÇÐèÒªÅжÏÇëÇóÊÇͨ¹ýGETÕÕ¾ÉPOST·½·¨·¢Ë͵ġ£ÎÒÃÇ¿ÉÒÔʹÓÃRequest¹¤¾ßµÄmethodÒªÁì»ñÈ¡ÇëÇóÒªÁì¡£ÀýÈ磺
use thinkRequest; $request = Request::instance(); if ($request->method() == 'GET') { // ´¦ÀíGETÇëÇó } else if ($request->method() == 'POST') { // ´¦ÀíPOSTÇëÇó }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇʹÓÃmethodÒªÁì»ñÈ¡ÇëÇóÒªÁ죬²¢Í¨¹ýifÓï¾äÅжÏÇëÇó·½·¨¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÔÚthinkphp¿ò¼ÜÖÐÇëÇó´ø²ÎÊýµÄÒªÁ죬°üÀ¨get¡¢postºÍrequestÒªÁì¡£±ðµÄ£¬ÎÒÃÇ»¹ÏÈÈÝÁË´øĬÈÏÖµµÄ»ñÈ¡·½·¨¡¢¶à¸ö²ÎÊý»ñÈ¡·½·¨ºÍ»ñÈ¡ÇëÇóÒªÁì¡£ÕâЩҪÁì¿ÉÒԺܺõØÖª×ãWeb¿ª·¢ÖÐÇëÇó²ÎÊýµÄÐèÇó£¬Ìá¸ßÁË¿ª·¢Ð§ÂÊ¡£
ÒÔÉϾÍÊÇthinkphpÇëÇó´ø²ÎµÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡