{"id":22823,"date":"2024-11-21T10:22:41","date_gmt":"2024-11-21T02:22:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22823\/"},"modified":"2024-11-21T10:22:41","modified_gmt":"2024-11-21T02:22:41","slug":"thinkphp-%e5%b7%a5%e4%bd%9c%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22823\/","title":{"rendered":"thinkphp \u5de5\u4f5c\u6d41\u7a0b"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u8fc5\u901f\u53d1\u5c55\uff0cweb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u53d8\u5f97\u8d8a\u6765\u8d8a\u6df1\u5165\u4eba\u5fc3\u3002\u800c\u73b0\u4ee3web\u5e94\u7528\u7a0b\u5e8f\u4e5f\u5fc5\u987b\u5177\u5907\u53ef\u9760\u7684\u6027\u80fd\u548c\u5b89\u5168\u4fdd\u969c\uff0c\u56e0\u6b64\uff0c\u91c7\u7528\u4e00\u4e2a\u9ad8\u5ea6\u4e13\u4e1a\u7684\u5f00\u53d1\u6846\u67b6\u6210\u4e3a\u4e86\u5fc5\u987b\u7684\u9009\u62e9\u3002thinkphp \u662f\u4e00\u4e2a\u5178\u578b\u7684php\u5f00\u53d1\u6846\u67b6\uff0c\u5728\u4e1a\u5185\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u548c\u5960\u5b9a\u7684\u5730\u4f4d\u3002\u672c\u6587\u5c06\u7b80\u8981\u4ecb\u7ecd thinkphp \u7684\u5de5\u4f5c\u6d41\u7a0b\u548c\u76f8\u5173\u7ec6\u8282\u3002<\/p>\n<p>\u4e00\u3001.htaccess \u914d\u7f6e<\/p>\n<p>ThinkPHP\u7684\u5de5\u4f5c\u6d41\u7a0b\u4ee5.htaccess \u914d\u7f6e\u6587\u4ef6\u6765\u542f\u52a8\uff0c\u5176\u5185\u8bbe\u7f6e\u4e86\u8bf8\u5982url\u91cd\u5b9a\u5411\u3001\u9632\u6b62\u6587\u4ef6\u88ab\u76f4\u63a5\u8bbf\u95ee\u7b49\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7ecf\u5178\u7684 .htaccess \u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5176\u4e2d\u4f7f\u7528\u4e86Apache\u7684mod_rewrite\u548cmod_proxy\u6a21\u5757\uff0c\u901a\u8fc7\u91cd\u5b9a\u5411\u548c\u900f\u660e\u4ee3\u7406\u6765\u5b9e\u73b0\u5b9e\u9645\u7684\u5165\u53e3\u6587\u4ef6\uff1a<\/p>\n<pre>&lt;ifmodule mod_rewrite.c&gt;\n\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^(.*)$ index.php?s=\/$1 [QSA,PT,L]\n\n&lt;\/ifmodule&gt;&lt;ifmodule mod_proxy.c&gt;\nProxyRequests Off\nProxyPass \/static !\nProxyPass \/ http:\/\/127.0.0.1:8080\/\n&lt;\/ifmodule&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e8c\u3001\u8def\u7531\u89e3\u6790<\/p>\n<p>\u5148\u6765\u770b\u4e0b\u9ed8\u8ba4\u7684\u8def\u7531\u89c4\u5219\uff1a\/\u6a21\u5757\u540d\/\u63a7\u5236\u5668\/\u64cd\u4f5c\u540d \u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u8def\u7531\u7684\u89e3\u6790\u662f\u6307\u5f53\u4e00\u4e2a\u8bf7\u6c42\u5230\u8fbe\u670d\u52a1\u5668\u65f6\uff0c\u670d\u52a1\u5668\u8981\u5bf9\u8bf7\u6c42\u7684URL\u505a\u4e00\u4e2a\u89e3\u6790\uff0c\u6765\u5224\u65ad\u5982\u4f55\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\uff0c\u4ee5\u53ca\u5bf9\u5e94\u7684\u63a7\u5236\u5668\u548c\u65b9\u6cd5\u662f\u54ea\u4e2a\u3002<\/p>\n<p>ThinkPHP \u7684\u8def\u7531\u89e3\u6790\u7684\u6838\u5fc3\u5728\u4e8e\u8def\u7531\u89e3\u6790\u7c7bThinkRoute\uff0c\u5728\u6846\u67b6\u7684\u6838\u5fc3\u5e93\u4e2d\uff0c\u5b9a\u4e49\u5728 thinkRoute.php \u4e2d\uff0c\u5176\u4e3b\u8981\u8d1f\u8d23\u5339\u914d URL \u8def\u5f84\u5230\u5bf9\u76f8\u5e94\u7684\u63a7\u5236\u5668\u548c\u65b9\u6cd5\u4e0a\u3002<\/p>\n<p>\u9ed8\u8ba4\u4f7f\u7528\u7684\u8def\u7531\u89e3\u6790\u89c4\u5219\u662f PATHINFO \u6a21\u5f0f\uff0c\u5373\u6309\u7167\u4e0a\u9762\u7684\u8bf4\u6cd5\uff0c\u89e3\u6790\u7684\u8def\u7531\u5e94\u8be5\u957f\u8fd9\u6837\uff1a<\/p>\n<pre>http:\/\/localhost\/index.php\/module\/Controller\/action<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e09\u3001\u63a7\u5236\u5668\u548c\u6a21\u5757<\/p>\n<p>\u5728 ThinkPHP \u4e2d\uff0c\u63a7\u5236\u5668\u8d1f\u8d23\u4e1a\u52a1\u903b\u8f91\u548c\u6570\u636e\u64cd\u4f5c\uff0c\u4e00\u4e2a\u63a7\u5236\u5668\u7c7b\u901a\u5e38\u5305\u62ec\u4e00\u4e9b\u65b9\u6cd5\u6765\u5904\u7406\u4e1a\u52a1\u903b\u8f91\uff0c\u901a\u5e38\u6211\u4eec\u53ef\u4ee5\u5728\u63a7\u5236\u5668\u91cc\u9762\u8c03\u7528\u6a21\u578b\uff08model\uff09\u6765\u5904\u7406\u6570\u636e\u3002<\/p>\n<p>\u5728\u6846\u67b6\u7684\u9ed8\u8ba4\u89c4\u5219\u4e2d\uff0c\u5b83\u4eec\u7684\u5173\u7cfb\u662f\uff1a<\/p>\n<p>1.\u4e00\u4e2a\u5e94\u7528\uff08application\uff09\u4e2d\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u6a21\u5757\uff08module\uff09\uff1b<br \/>2.\u4e00\u4e2a\u6a21\u5757\uff08module\uff09\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u63a7\u5236\u5668\uff08controller\uff09\uff1b<br \/>3.\u4e00\u4e2a\u63a7\u5236\u5668\uff08controller\uff09\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u65b9\u6cd5\uff08action\uff09\u3002<\/p>\n<p>\u56db\u3001\u6570\u636e\u6a21\u578b<\/p>\n<p>\u6570\u636e\u6a21\u578b\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206\u3002\u6570\u636e\u6a21\u578b\u51b3\u5b9a\u4e86\u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u64cd\u4f5c\u3001\u5982\u4f55\u5904\u7406\u548c\u5b58\u50a8\u6570\u636e\u3002ThinkPHP \u4e2d\u7684\u6570\u636e\u6a21\u578b\u91c7\u7528\u4e86\u4e00\u79cd\u79f0\u4e3a ActiveRecord \u7684\u6570\u636e\u8bbf\u95ee\u6a21\u5f0f\u3002ActiveRecord\u5c06\u4e00\u4e2a\u5bf9\u8c61\u6620\u5c04\u5230 SQL \u6570\u636e\u5e93\u4e2d\u7684\u4e00\u4e2a\u8868\uff0c\u5e76\u5728\u7a0b\u5e8f\u4e2d\u6765\u8868\u793a\u64cd\u4f5c\u8868\u7684\u6570\u636e\u884c\u3002<\/p>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c\u6846\u67b6\u7ea6\u5b9a\u5728 \/application \u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a Model \u76ee\u5f55\uff0c\u6240\u6709\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u6a21\u578b\u90fd\u5e94\u8be5\u653e\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff0c\u5e76\u4e14\u901a\u5e38\u4e3a\u4e86\u65b9\u4fbf\u7ef4\u62a4\u548c\u76f8\u5e94\u7684\u6a21\u5757\u6765\u8fdb\u884c\u5212\u5206\u3002<\/p>\n<p>\u4e94\u3001\u89c6\u56fe\u5c42<\/p>\n<p>\u89c6\u56fe\u5c42\u8d1f\u8d23 HTML \u9875\u9762\u7684\u751f\u6210\u548c\u5c55\u793a\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u4e00\u822c\u91c7\u7528\u6a21\u677f\u5f15\u64ce\u6765\u6784\u5efa\u89c6\u56fe\u5c42\u3002ThinkPHP \u5185\u7f6e\u4e86\u4e24\u79cd\u6a21\u7248\u5f15\u64ce\uff0c\u4e00\u79cd\u662f\u539f\u751f\u7684\u6a21\u677f\u5f15\u64ce\uff0c\u4e00\u79cd\u662f\u57fa\u4e8ePHP\u7684\u6a21\u677f\u5f15\u64ce\u3002<\/p>\n<p>ThinkPHP \u7684\u6a21\u677f\u6587\u4ef6\u901a\u5e38\u4ee5 .html \u6216 .php \u7684\u6269\u5c55\u540d\u7ed3\u5c3e\uff0c\u4f4d\u4e8e\u6a21\u677f\u76ee\u5f55 \/application\/views\/$module\/$controller\/\u3002<\/p>\n<p>\u516d\u3001\u603b\u7ed3<\/p>\n<p>ThinkPHP \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684 PHP \u5f00\u53d1\u6846\u67b6\u3002\u5176\u826f\u597d\u7684\u8bbe\u8ba1\u548c\u7075\u6d3b\u7684\u67b6\u6784\u4f7f\u5f97\u5b83\u6210\u4e3a\u5f88\u591a\u9879\u76ee\u7684\u9996\u9009\u6846\u67b6\u3002\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86 ThinkPHP \u7684\u5de5\u4f5c\u6d41\u7a0b\u548c\u76f8\u5173\u7ec6\u8282\uff0c\u5305\u62ec .htaccess \u914d\u7f6e\uff0c\u8def\u7531\u89e3\u6790\uff0c\u63a7\u5236\u5668\u548c\u6a21\u5757\uff0c\u6570\u636e\u6a21\u578b\u548c\u89c6\u56fe\u5c42\u3002\u638c\u63e1\u8fd9\u4e9b\u77e5\u8bc6\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u66f4\u597d\u5730\u7406\u89e3 ThinkPHP\uff0c\u5e76\u4e14\u80fd\u591f\u66f4\u52a0\u9ad8\u6548\u5730\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fthinkphp \u5de5\u4f5c\u6d41\u7a0b\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>\u968f\u7740\u4e92\u8054\u7f51\u7684\u8fc5\u901f\u53d1\u5c55\uff0cweb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u53d8\u5f97\u8d8a\u6765\u8d8a\u6df1\u5165\u4eba\u5fc3\u3002\u800c\u73b0\u4ee3web\u5e94\u7528\u7a0b\u5e8f\u4e5f\u5fc5\u987b\u5177\u5907\u53ef\u9760\u7684\u6027\u80fd\u548c\u5b89\u5168\u4fdd\u969c\uff0c\u56e0\u6b64\uff0c\u91c7\u7528\u4e00\u4e2a\u9ad8\u5ea6\u4e13\u4e1a\u7684\u5f00\u53d1\u6846\u67b6\u6210\u4e3a\u4e86\u5fc5\u987b\u7684\u9009\u62e9\u3002thinkphp \u662f\u4e00\u4e2a\u5178\u578b\u7684php\u5f00\u53d1\u6846\u67b6\uff0c\u5728\u4e1a\u5185\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u548c\u5960\u5b9a\u7684\u5730\u4f4d\u3002\u672c\u6587\u5c06\u7b80\u8981\u4ecb\u7ecd thinkphp \u7684\u5de5\u4f5c\u6d41\u7a0b\u548c\u76f8\u5173\u7ec6\u8282\u3002 \u4e00\u3001.htaccess \u914d\u7f6e ThinkPHP\u7684\u5de5\u4f5c\u6d41\u7a0b\u4ee5.htaccess \u914d\u7f6e\u6587\u4ef6\u6765\u542f\u52a8\uff0c\u5176\u5185\u8bbe\u7f6e\u4e86\u8bf8\u5982url\u91cd\u5b9a\u5411\u3001\u9632\u6b62\u6587\u4ef6\u88ab\u76f4\u63a5\u8bbf\u95ee\u7b49\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7ecf\u5178\u7684 .htaccess \u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u5176\u4e2d\u4f7f\u7528\u4e86Apache\u7684mod_rewrite\u548cmod_proxy\u6a21\u5757\uff0c\u901a\u8fc7\u91cd\u5b9a\u5411\u548c\u900f\u660e\u4ee3\u7406\u6765\u5b9e\u73b0\u5b9e\u9645\u7684\u5165\u53e3\u6587\u4ef6\uff1a &lt;ifmodule mod_rewrite.c&gt; RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?s=\/$1 [QSA,PT,L] &lt;\/ifmodule&gt;&lt;ifmodule mod_proxy.c&gt; ProxyRequests Off ProxyPass \/static ! ProxyPass \/ http:\/\/127.0.0.1:8080\/ &lt;\/ifmodule&gt; \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u8def\u7531\u89e3\u6790 \u5148\u6765\u770b\u4e0b\u9ed8\u8ba4\u7684\u8def\u7531\u89c4\u5219\uff1a\/\u6a21\u5757\u540d\/\u63a7\u5236\u5668\/\u64cd\u4f5c\u540d \u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8def\u7531\u7684\u89e3\u6790\u662f\u6307\u5f53\u4e00\u4e2a\u8bf7\u6c42\u5230\u8fbe\u670d\u52a1\u5668\u65f6\uff0c\u670d\u52a1\u5668\u8981\u5bf9\u8bf7\u6c42\u7684URL\u505a\u4e00\u4e2a\u89e3\u6790\uff0c\u6765\u5224\u65ad\u5982\u4f55\u5904\u7406\u8fd9\u4e2a\u8bf7\u6c42\uff0c\u4ee5\u53ca\u5bf9\u5e94\u7684\u63a7\u5236\u5668\u548c\u65b9\u6cd5\u662f\u54ea\u4e2a\u3002 ThinkPHP \u7684\u8def\u7531\u89e3\u6790\u7684\u6838\u5fc3\u5728\u4e8e\u8def\u7531\u89e3\u6790\u7c7bThinkRoute\uff0c\u5728\u6846\u67b6\u7684\u6838\u5fc3\u5e93\u4e2d\uff0c\u5b9a\u4e49\u5728 thinkRoute.php \u4e2d\uff0c\u5176\u4e3b\u8981\u8d1f\u8d23\u5339\u914d URL \u8def\u5f84\u5230\u5bf9\u76f8\u5e94\u7684\u63a7\u5236\u5668\u548c\u65b9\u6cd5\u4e0a\u3002 \u9ed8\u8ba4\u4f7f\u7528\u7684\u8def\u7531\u89e3\u6790\u89c4\u5219\u662f PATHINFO \u6a21\u5f0f\uff0c\u5373\u6309\u7167\u4e0a\u9762\u7684\u8bf4\u6cd5\uff0c\u89e3\u6790\u7684\u8def\u7531\u5e94\u8be5\u957f\u8fd9\u6837\uff1a http:\/\/localhost\/index.php\/module\/Controller\/action \u767b\u5f55\u540e\u590d\u5236 \u4e09\u3001\u63a7\u5236\u5668\u548c\u6a21\u5757 \u5728 ThinkPHP [&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-22823","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22823","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=22823"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22823\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}