{"id":22866,"date":"2024-11-21T12:06:45","date_gmt":"2024-11-21T04:06:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22866\/"},"modified":"2024-11-21T12:06:45","modified_gmt":"2024-11-21T04:06:45","slug":"%e6%80%8e%e4%b9%88%e5%9c%a8%e7%94%b5%e8%84%91%e8%bf%90%e8%a1%8cthinkphp","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22866\/","title":{"rendered":"\u600e\u4e48\u5728\u7535\u8111\u8fd0\u884cthinkphp"},"content":{"rendered":"<p>\u5728\u5982\u4eca\u4e92\u8054\u7f51\u7684\u65f6\u4ee3\uff0c\u7f51\u7ad9\u7684\u5f00\u53d1\u5df2\u7ecf\u6210\u4e3a\u4e86\u4e00\u4e2a\u975e\u5e38\u706b\u70ed\u7684\u884c\u4e1a\u3002\u5f00\u53d1\u4e00\u4e2a\u5b8c\u6574\u7684\u7f51\u7ad9\u9700\u8981\u975e\u5e38\u591a\u7684\u5de5\u4f5c\u548c\u6280\u672f\u652f\u6301\uff0c\u5728\u8fd9\u4e9b\u6280\u672f\u4e2d\uff0c\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6280\u672f\u5c31\u662fphp\u6846\u67b6\uff0c\u5176\u4e2dthinkphp\u662f\u6700\u5e38\u7528\u7684\u4e00\u4e2a\u3002<\/p>\n<p>ThinkPHP\u662f\u4e00\u4e2a\u5f00\u6e90\u7684PHP\u6846\u67b6\uff0c\u5176\u51fa\u73b0\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u7ef4\u62a4\u3001\u4f18\u96c5\u3001\u7b80\u6d01\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002ThinkPHP\u6846\u67b6\u96c6\u6210\u4e86\u5927\u91cf\u7684\u6a21\u5757\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u53d1\u51fa\u9ad8\u8d28\u91cf\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728\u7535\u8111\u4e0a\u8fd0\u884cThinkPHP\u3002<\/p>\n<p>\u4e00\u3001\u73af\u5883\u914d\u7f6e<\/p>\n<p>\u5728\u8fd0\u884cThinkPHP\u4e4b\u524d\uff0c\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u5f00\u53d1\u73af\u5883\uff1a<\/p>\n<ol>\n<li>PHP \u73af\u5883\uff1aPHP 5.6+\uff0c\u63a8\u8350\u4f7f\u7528 PHP7.2+\uff0c\u5177\u4f53\u7684\u5b89\u88c5\u65b9\u6cd5\u53ef\u4ee5\u53c2\u7167PHP\u5b98\u7f51\u7ed9\u51fa\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<li>MySQL \u6570\u636e\u5e93\uff1a\u63a8\u8350\u4f7f\u7528 MySqli \u6216\u8005 PDO \u6570\u636e\u5e93\u9a71\u52a8\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>\u670d\u52a1\u5668\u73af\u5883\uff1aApache \u6216\u8005 Nginx\uff0c\u63a8\u8350\u4f7f\u7528 Apache\u3002<\/li>\n<li>Composer \u5de5\u5177\uff1a\u5b89\u88c5Composer\u53ef\u4ee5\u4f7f\u7528PHP\u4f9d\u8d56\u7ba1\u7406\u5668\uff0c\u5c06\u6846\u67b6\u6240\u4f9d\u8d56\u7684\u5916\u90e8\u5e93\uff0c\u901a\u8fc7\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4f9d\u8d56\u7ba1\u7406\u3002\u5177\u4f53\u7684\u5b89\u88c5\u65b9\u6cd5\u53ef\u4ee5\u53c2\u7167TinkPHP\u5b98\u7f51\u4e0a\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p>\u4e8c\u3001\u4e0b\u8f7dThinkPHP\u6846\u67b6<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728\u73af\u5883\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u4e0b\u8f7dThinkPHP\u6846\u67b6\u4e86\u3002\u53ef\u4ee5\u5728ThinkPHP\u5b98\u7f51\u4e0a\u4e0b\u8f7d\u5230\u6700\u65b0\u7248\u7684\u6846\u67b6\u4ee3\u7801\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4eceGithub\u4e0b\u8f7dThinkPHP\u9879\u76ee\u6e90\u4ee3\u7801\u3002<\/p>\n<p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u5c06\u6846\u67b6\u6587\u4ef6\u89e3\u538b\u540e\u653e\u7f6e\u5230\u670d\u52a1\u5668\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u3002<\/p>\n<p>\u4e09\u3001\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5728\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\uff0c\u9700\u8981\u5148\u8bbe\u7f6e\u4e00\u4e2a\u865a\u62df\u4e3b\u673a\u6765\u8bbf\u95eeThinkPHP\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728Apache\u4e2d\uff0c\u53ef\u4ee5\u7f16\u8f91httpd.conf\u6216\u8005\u6dfb\u52a0\u4e00\u4e2a\u4e13\u95e8\u7684\u865a\u62df\u4e3b\u673a\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u5728httpd.conf\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;virtualhost&gt;\n    ServerName test.com         #\u8bbe\u7f6e\u57df\u540d\n    DocumentRoot \"\/usr\/local\/var\/www\/test\"   #\u6307\u5411\u5e94\u7528\u7a0b\u5e8f\u7684\u76ee\u5f55\n    &lt;directory&gt;\n        AllowOverride All          #\u5141\u8bb8.htaccess\n        Require all granted\n    &lt;\/directory&gt;&lt;\/virtualhost&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b8c\u6210\u865a\u62df\u4e3b\u673a\u7684\u8bbe\u7f6e\u540e\uff0c\u5f00\u59cb\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u3002\u5c06\u89e3\u538b\u51fa\u6765\u7684\u6846\u67b6\u6587\u4ef6\u590d\u5236\u5230\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\uff0c\u914d\u7f6econfig.php\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002<\/p>\n<p>\u56db\u3001\u4f7f\u7528ThinkPHP<\/p>\n<p>\u4f7f\u7528ThinkPHP\u8fdb\u884c\u5f00\u53d1\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u51fa\u9ad8\u8d28\u91cf\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684ORM\uff0c\u6a21\u677f\u5f15\u64ce\u548c\u7f13\u5b58\u7b49\u5de5\u5177\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa\u63a7\u5236\u5668<\/li>\n<\/ol>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aIndex\u63a7\u5236\u5668\uff0c\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u76ee\u5f55\u4e0b\u7684Index\u76ee\u5f55\u4e2d\u521b\u5efaIndexController.php\u6587\u4ef6\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;?php namespace appindexcontroller;\n\n    class IndexController\n    {\n        public function index()\n        {\n            return 'Hello ThinkPHP\uff01';\n        }\n    }\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u521b\u5efa\u6a21\u677f<\/li>\n<\/ol>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u6839\u76ee\u5f55\u4e0b\u521b\u5efaindex.html\u6587\u4ef6\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\n\n\n    &lt;meta charset=\"UTF-8\"&gt;&lt;title&gt;\u6b22\u8fce\u6765\u5230ThinkPHP\uff1a{$title}&lt;\/title&gt;&lt;h1&gt;{$content}&lt;\/h1&gt;\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>3.\u4fee\u6539\u8def\u7531<\/p>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u6839\u76ee\u5f55\u4e0b\u7684route.php\u6587\u4ef6\u4e2d\u6dfb\u52a0\u8def\u7531\u89c4\u5219\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;?php use thinkRoute;\n\n    Route::get('hello\/:name', 'index\/index\/hello'); \/\/\u6dfb\u52a0\u8def\u7531\u89c4\u5219\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f<\/li>\n<\/ol>\n<p>\u8bbf\u95ee http:\/\/test.com\uff0c\u5c06\u4f1a\u663e\u793a\u201cHello ThinkPHP\uff01\u201d\uff0c\u5373\u5f00\u53d1\u6210\u529f\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728\u7535\u8111\u4e0a\u8fd0\u884cThinkPHP\uff0c\u901a\u8fc7\u73af\u5883\u914d\u7f6e\u3001\u4e0b\u8f7d\u6846\u67b6\u3001\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u3001\u4f7f\u7528ThinkPHP\u7684\u56db\u4e2a\u6b65\u9aa4\uff0c\u5feb\u901f\u5730\u6784\u5efa\u4e00\u4e2a\u5b8c\u6574\u7684\u7f51\u7ad9\u3002\u76f8\u4fe1\u901a\u8fc7\u672c\u6587\u7684\u5b66\u4e60\uff0c\u5bf9\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u4e86\u89e3ThinkPHP\u7684\u57fa\u7840\u77e5\u8bc6\u548c\u5e94\u7528\u6709\u5f88\u5927\u7684\u5e2e\u52a9\uff0c\u80fd\u591f\u66f4\u52a0\u5feb\u901f\u5730\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5728\u7535\u8111\u8fd0\u884cthinkphp\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>\u5728\u5982\u4eca\u4e92\u8054\u7f51\u7684\u65f6\u4ee3\uff0c\u7f51\u7ad9\u7684\u5f00\u53d1\u5df2\u7ecf\u6210\u4e3a\u4e86\u4e00\u4e2a\u975e\u5e38\u706b\u70ed\u7684\u884c\u4e1a\u3002\u5f00\u53d1\u4e00\u4e2a\u5b8c\u6574\u7684\u7f51\u7ad9\u9700\u8981\u975e\u5e38\u591a\u7684\u5de5\u4f5c\u548c\u6280\u672f\u652f\u6301\uff0c\u5728\u8fd9\u4e9b\u6280\u672f\u4e2d\uff0c\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6280\u672f\u5c31\u662fphp\u6846\u67b6\uff0c\u5176\u4e2dthinkphp\u662f\u6700\u5e38\u7528\u7684\u4e00\u4e2a\u3002 ThinkPHP\u662f\u4e00\u4e2a\u5f00\u6e90\u7684PHP\u6846\u67b6\uff0c\u5176\u51fa\u73b0\u65e8\u5728\u5e2e\u52a9\u5f00\u53d1\u8005\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u7ef4\u62a4\u3001\u4f18\u96c5\u3001\u7b80\u6d01\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002ThinkPHP\u6846\u67b6\u96c6\u6210\u4e86\u5927\u91cf\u7684\u6a21\u5757\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u5feb\u901f\u5f00\u53d1\u51fa\u9ad8\u8d28\u91cf\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728\u7535\u8111\u4e0a\u8fd0\u884cThinkPHP\u3002 \u4e00\u3001\u73af\u5883\u914d\u7f6e \u5728\u8fd0\u884cThinkPHP\u4e4b\u524d\uff0c\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u7684\u5f00\u53d1\u73af\u5883\uff1a PHP \u73af\u5883\uff1aPHP 5.6+\uff0c\u63a8\u8350\u4f7f\u7528 PHP7.2+\uff0c\u5177\u4f53\u7684\u5b89\u88c5\u65b9\u6cd5\u53ef\u4ee5\u53c2\u7167PHP\u5b98\u7f51\u7ed9\u51fa\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002 MySQL \u6570\u636e\u5e93\uff1a\u63a8\u8350\u4f7f\u7528 MySqli \u6216\u8005 PDO \u6570\u636e\u5e93\u9a71\u52a8\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7684\u6570\u636e\u5e93\u3002 \u670d\u52a1\u5668\u73af\u5883\uff1aApache \u6216\u8005 Nginx\uff0c\u63a8\u8350\u4f7f\u7528 Apache\u3002 Composer \u5de5\u5177\uff1a\u5b89\u88c5Composer\u53ef\u4ee5\u4f7f\u7528PHP\u4f9d\u8d56\u7ba1\u7406\u5668\uff0c\u5c06\u6846\u67b6\u6240\u4f9d\u8d56\u7684\u5916\u90e8\u5e93\uff0c\u901a\u8fc7\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u4f9d\u8d56\u7ba1\u7406\u3002\u5177\u4f53\u7684\u5b89\u88c5\u65b9\u6cd5\u53ef\u4ee5\u53c2\u7167TinkPHP\u5b98\u7f51\u4e0a\u7684\u8bf4\u660e\u8fdb\u884c\u5b89\u88c5\u3002 \u4e8c\u3001\u4e0b\u8f7dThinkPHP\u6846\u67b6 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728\u73af\u5883\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u4e0b\u8f7dThinkPHP\u6846\u67b6\u4e86\u3002\u53ef\u4ee5\u5728ThinkPHP\u5b98\u7f51\u4e0a\u4e0b\u8f7d\u5230\u6700\u65b0\u7248\u7684\u6846\u67b6\u4ee3\u7801\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4eceGithub\u4e0b\u8f7dThinkPHP\u9879\u76ee\u6e90\u4ee3\u7801\u3002 \u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u5c06\u6846\u67b6\u6587\u4ef6\u89e3\u538b\u540e\u653e\u7f6e\u5230\u670d\u52a1\u5668\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u3002 \u4e09\u3001\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f \u5728\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u4e4b\u524d\uff0c\u9700\u8981\u5148\u8bbe\u7f6e\u4e00\u4e2a\u865a\u62df\u4e3b\u673a\u6765\u8bbf\u95eeThinkPHP\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728Apache\u4e2d\uff0c\u53ef\u4ee5\u7f16\u8f91httpd.conf\u6216\u8005\u6dfb\u52a0\u4e00\u4e2a\u4e13\u95e8\u7684\u865a\u62df\u4e3b\u673a\u914d\u7f6e\u6587\u4ef6\u3002 \u5728httpd.conf\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a &lt;virtualhost&gt; ServerName test.com #\u8bbe\u7f6e\u57df\u540d DocumentRoot &#8220;\/usr\/local\/var\/www\/test&#8221; #\u6307\u5411\u5e94\u7528\u7a0b\u5e8f\u7684\u76ee\u5f55 &lt;directory&gt; AllowOverride All #\u5141\u8bb8.htaccess Require all granted &lt;\/directory&gt;&lt;\/virtualhost&gt; \u767b\u5f55\u540e\u590d\u5236 \u5b8c\u6210\u865a\u62df\u4e3b\u673a\u7684\u8bbe\u7f6e\u540e\uff0c\u5f00\u59cb\u914d\u7f6e\u5e94\u7528\u7a0b\u5e8f\u3002\u5c06\u89e3\u538b\u51fa\u6765\u7684\u6846\u67b6\u6587\u4ef6\u590d\u5236\u5230\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\uff0c\u914d\u7f6econfig.php\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002 \u56db\u3001\u4f7f\u7528ThinkPHP \u4f7f\u7528ThinkPHP\u8fdb\u884c\u5f00\u53d1\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u51fa\u9ad8\u8d28\u91cf\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684ORM\uff0c\u6a21\u677f\u5f15\u64ce\u548c\u7f13\u5b58\u7b49\u5de5\u5177\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a \u521b\u5efa\u63a7\u5236\u5668 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3aIndex\u63a7\u5236\u5668\uff0c\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u76ee\u5f55\u4e0b\u7684Index\u76ee\u5f55\u4e2d\u521b\u5efaIndexController.php\u6587\u4ef6\u3002\u4ee3\u7801\u5982\u4e0b\uff1a &lt;?php namespace appindexcontroller; class IndexController { public [&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-22866","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22866","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=22866"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22866\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}