{"id":22738,"date":"2024-11-21T14:31:37","date_gmt":"2024-11-21T06:31:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22738\/"},"modified":"2024-11-21T14:31:37","modified_gmt":"2024-11-21T06:31:37","slug":"thinkphp%e6%80%8e%e4%b9%88%e6%8f%90%e4%ba%a4%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22738\/","title":{"rendered":"thinkphp\u600e\u4e48\u63d0\u4ea4\u6570\u636e"},"content":{"rendered":"<p>\u4f7f\u7528thinkphp\u6846\u67b6\u8fdb\u884c\u5f00\u53d1\uff0c\u63d0\u4ea4\u6570\u636e\u662f\u975e\u5e38\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u5728\u8be5\u6846\u67b6\u4e2d\uff0c\u63d0\u4ea4\u6570\u636e\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<h2>1. GET\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<\/h2>\n<p>\u4f7f\u7528GET\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u901a\u8fc7URL\u5730\u5740\u4f20\u9012\u53c2\u6570\uff0c\u8be5\u65b9\u5f0f\u9002\u7528\u4e8e\u5c11\u91cf\u7684\u6570\u636e\uff0c\u6bd4\u5982\u641c\u7d22\u5173\u952e\u5b57\u3001\u5206\u9875\u7b49\u64cd\u4f5c\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6GET\u53c2\u6570\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6\u5355\u4e2aGET\u53c2\u6570\n$param = input('get.param');\n\n\/\/ \u83b7\u53d6\u6240\u6709GET\u53c2\u6570\n$params = input('get.');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>2. POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<\/h2>\n<p>\u4f7f\u7528POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5411\u670d\u52a1\u5668\u53d1\u9001\u5927\u91cf\u6570\u636e\uff0c\u6bd4\u5982\u8868\u5355\u6570\u636e\u3001\u6587\u4ef6\u4e0a\u4f20\u7b49\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6POST\u53c2\u6570\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6\u5355\u4e2aPOST\u53c2\u6570\n$param = input('post.param');\n\n\/\/ \u83b7\u53d6\u6240\u6709POST\u53c2\u6570\n$params = input('post.');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>3. JSON\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<\/h2>\n<p>\u4f7f\u7528JSON\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5728\u524d\u540e\u7aef\u5206\u79bb\u7684\u5f00\u53d1\u4e2d\u4f7f\u7528\uff0c\u901a\u8fc7AJAX\u7b49\u65b9\u5f0f\u5c06JSON\u6570\u636e\u683c\u5f0f\u53d1\u9001\u5230\u670d\u52a1\u5668\u7aef\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6JSON\u53c2\u6570\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6JSON\u53c2\u6570\n$json = file_get_contents('php:\/\/input');\n$params = json_decode($json, true);   \/\/ \u5c06JSON\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>4. PUT\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<\/h2>\n<p>\u4f7f\u7528PUT\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5bf9\u670d\u52a1\u5668\u4e0a\u5df2\u6709\u8d44\u6e90\u8fdb\u884c\u4fee\u6539\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6PUT\u53c2\u6570\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u83b7\u53d6PUT\u53c2\u6570\n$put = file_get_contents(\"php:\/\/input\");\nparse_str($put, $params);   \/\/ \u5c06PUT\u53c2\u6570\u8f6c\u6362\u6210\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>5. DELETE\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e<\/h2>\n<p>\u4f7f\u7528DELETE\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5220\u9664\u670d\u52a1\u5668\u4e0a\u5df2\u6709\u8d44\u6e90\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6DELETE\u53c2\u6570\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6DELETE\u53c2\u6570\n$delete = $_SERVER['QUERY_STRING'];\nparse_str($delete, $params);   \/\/ \u5c06DELETE\u53c2\u6570\u8f6c\u6362\u6210\u6570\u7ec4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9664\u4e86\u4ee5\u4e0a5\u79cd\u65b9\u5f0f\uff0cThinkPHP\u6846\u67b6\u8fd8\u63d0\u4f9b\u4e86input\u5bf9\u8c61\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u83b7\u53d6\u63d0\u4ea4\u7684\u6570\u636e\uff1a<\/p>\n<pre>\/\/ \u83b7\u53d6All\u53c2\u6570\uff08\u5305\u62ecGET\u3001POST\u3001JSON\u3001PUT\u3001DELETE\uff09\n$params = input('param.');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u5f0f\u83b7\u53d6\u63d0\u4ea4\u7684\u6570\u636e\u3002\u540c\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5b89\u5168\u6027\uff0c\u5bf9\u4e8e\u7528\u6237\u63d0\u4ea4\u7684\u6570\u636e\u9700\u8981\u8fdb\u884c\u8fc7\u6ee4\u548c\u9a8c\u8bc1\uff0c\u9632\u6b62\u6ce8\u5165\u548c\u653b\u51fb\u7b49\u6076\u610f\u884c\u4e3a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fthinkphp\u600e\u4e48\u63d0\u4ea4\u6570\u636e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528thinkphp\u6846\u67b6\u8fdb\u884c\u5f00\u53d1\uff0c\u63d0\u4ea4\u6570\u636e\u662f\u975e\u5e38\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u5728\u8be5\u6846\u67b6\u4e2d\uff0c\u63d0\u4ea4\u6570\u636e\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5177\u4f53\u5982\u4e0b\uff1a 1. GET\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e \u4f7f\u7528GET\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u901a\u8fc7URL\u5730\u5740\u4f20\u9012\u53c2\u6570\uff0c\u8be5\u65b9\u5f0f\u9002\u7528\u4e8e\u5c11\u91cf\u7684\u6570\u636e\uff0c\u6bd4\u5982\u641c\u7d22\u5173\u952e\u5b57\u3001\u5206\u9875\u7b49\u64cd\u4f5c\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6GET\u53c2\u6570\uff1a \/\/ \u83b7\u53d6\u5355\u4e2aGET\u53c2\u6570 $param = input(&#8216;get.param&#8217;); \/\/ \u83b7\u53d6\u6240\u6709GET\u53c2\u6570 $params = input(&#8216;get.&#8217;); \u767b\u5f55\u540e\u590d\u5236 2. POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e \u4f7f\u7528POST\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5411\u670d\u52a1\u5668\u53d1\u9001\u5927\u91cf\u6570\u636e\uff0c\u6bd4\u5982\u8868\u5355\u6570\u636e\u3001\u6587\u4ef6\u4e0a\u4f20\u7b49\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6POST\u53c2\u6570\uff1a \/\/ \u83b7\u53d6\u5355\u4e2aPOST\u53c2\u6570 $param = input(&#8216;post.param&#8217;); \/\/ \u83b7\u53d6\u6240\u6709POST\u53c2\u6570 $params = input(&#8216;post.&#8217;); \u767b\u5f55\u540e\u590d\u5236 3. JSON\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e \u4f7f\u7528JSON\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5728\u524d\u540e\u7aef\u5206\u79bb\u7684\u5f00\u53d1\u4e2d\u4f7f\u7528\uff0c\u901a\u8fc7AJAX\u7b49\u65b9\u5f0f\u5c06JSON\u6570\u636e\u683c\u5f0f\u53d1\u9001\u5230\u670d\u52a1\u5668\u7aef\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6JSON\u53c2\u6570\uff1a \/\/ \u83b7\u53d6JSON\u53c2\u6570 $json = file_get_contents(&#8216;php:\/\/input&#8217;); $params = json_decode($json, true); \/\/ \u5c06JSON\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4 \u767b\u5f55\u540e\u590d\u5236 4. PUT\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e \u4f7f\u7528PUT\u65b9\u5f0f\u63d0\u4ea4\u6570\u636e\uff0c\u53ef\u4ee5\u5bf9\u670d\u52a1\u5668\u4e0a\u5df2\u6709\u8d44\u6e90\u8fdb\u884c\u4fee\u6539\u3002\u5728ThinkPHP\u6846\u67b6\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u83b7\u53d6PUT\u53c2\u6570\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u83b7\u53d6PUT\u53c2\u6570 $put = file_get_contents(&#8220;php:\/\/input&#8221;); parse_str($put, $params); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22738","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22738"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22738\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}