{"id":23727,"date":"2024-11-21T12:16:01","date_gmt":"2024-11-21T04:16:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/23727\/"},"modified":"2024-11-21T12:16:01","modified_gmt":"2024-11-21T04:16:01","slug":"thinkphp5%e6%80%8e%e4%b9%88%e9%85%8d%e7%bd%ae-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/23727\/","title":{"rendered":"thinkphp5\u600e\u4e48\u914d\u7f6e"},"content":{"rendered":"<p>\u968f\u7740\u4e92\u8054\u7f51\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cphp\u8bed\u8a00\u5df2\u7ecf\u6210\u4e3a\u4e86\u975e\u5e38\u6d41\u884c\u7684\u4e00\u79cdweb\u5f00\u53d1\u8bed\u8a00\uff0c\u800cthinkphp\u5219\u662fphp\u4e2d\u8f83\u4e3a\u4f18\u79c0\u7684\u4e00\u79cd\u5f00\u53d1\u6846\u67b6\u3002\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecdthinkphp5\u7684\u914d\u7f6e\uff0c\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u4f7f\u7528\u8fd9\u6b3e\u6846\u67b6\u3002<\/p>\n<p>\u4e00\u3001\u73af\u5883\u8981\u6c42<\/p>\n<p>\u5728\u5f00\u59cb\u914d\u7f6e\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u73af\u5883\u8fdb\u884c\u4e00\u4e9b\u8981\u6c42\u3002ThinkPHP5\u9700\u8981PHP5.4\u53ca\u4ee5\u4e0a\u7248\u672c\u652f\u6301\uff0c\u5e76\u4e14\u9700\u8981MySQL 5.0\u53ca\u4ee5\u4e0a\u7248\u672c\u3002\u5982\u679c\u60a8\u7684\u670d\u52a1\u5668\u6ee1\u8db3\u8fd9\u4e9b\u6761\u4ef6\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u914d\u7f6e\u8fd9\u4e2a\u6846\u67b6\u4e86\u3002<\/p>\n<p>\u4e8c\u3001\u76ee\u5f55\u7ed3\u6784\u53ca\u6587\u4ef6\u7528\u9014<\/p>\n<p>\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0bThinkPHP5\u7684\u76ee\u5f55\u7ed3\u6784\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>ThinkPHP<br \/>\u251c\u2500app &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u5e94\u7528\u76ee\u5f55<br \/>\u2502 &nbsp;\u251c\u2500controller &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u63a7\u5236\u5668\u76ee\u5f55<br \/>\u2502 &nbsp;\u251c\u2500model &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u6a21\u578b\u76ee\u5f55<br \/>\u2502 &nbsp;\u2514\u2500view &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u89c6\u56fe\u76ee\u5f55<br \/>\u251c\u2500config &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55<br \/>\u251c\u2500public &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u5165\u53e3\u6587\u4ef6\u53ca\u8d44\u6e90\u76ee\u5f55<br \/>\u2502 &nbsp;\u251c\u2500static &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u9759\u6001\u8d44\u6e90\u76ee\u5f55<br \/>\u2502 &nbsp;\u251c\u2500.htaccess &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;htaccess\u6587\u4ef6<br \/>\u2502 &nbsp;\u251c\u2500favicon.ico &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u7f51\u7ad9\u56fe\u6807<br \/>\u2502 &nbsp;\u2514\u2500index.php &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u5165\u53e3\u6587\u4ef6<br \/>\u251c\u2500route &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u8def\u7531\u914d\u7f6e\u76ee\u5f55<br \/>\u251c\u2500runtime &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u8fd0\u884c\u65f6\u76ee\u5f55<br \/>\u251c\u2500thinkphp &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ThinkPHP\u6846\u67b6\u7cfb\u7edf\u76ee\u5f55<br \/>\u251c\u2500vendor &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Composer\u7c7b\u5e93\u76ee\u5f55<br \/>\u251c\u2500.htaccess &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; htaccess\u6587\u4ef6<br \/>\u251c\u2500composer.json &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Composer\u914d\u7f6e\u6587\u4ef6<br \/>\u251c\u2500README.md &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u6846\u67b6\u8bf4\u660e\u6587\u4ef6<br \/>\u2514\u2500think &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u547d\u4ee4\u884c\u5165\u53e3\u6587\u4ef6<\/p>\n<p>\u5176\u4e2d\uff0c\u5404\u6587\u4ef6\u5939\u7684\u4f5c\u7528\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>app\uff1a\u5e94\u7528\u76ee\u5f55\uff0c\u7528\u4e8e\u5b58\u653e\u63a7\u5236\u5668\u3001\u6a21\u578b\u3001\u89c6\u56fe\u7b49\u6587\u4ef6\u3002<\/li>\n<li>config\uff1a\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\uff0c\u5305\u62ec\u6570\u636e\u5e93\u914d\u7f6e\u3001\u8def\u7531\u914d\u7f6e\u7b49\u3002<\/li>\n<li>public\uff1a\u5165\u53e3\u6587\u4ef6\u53ca\u8d44\u6e90\u76ee\u5f55\uff0c\u5305\u62ec\u9759\u6001\u8d44\u6e90\u76ee\u5f55\u3001\u5165\u53e3\u6587\u4ef6\u53cahtaccess\u6587\u4ef6\u3002<\/li>\n<li>route\uff1a\u8def\u7531\u914d\u7f6e\u76ee\u5f55\uff0c\u914d\u7f6e\u8def\u7531\u89c4\u5219\u3002<\/li>\n<li>runtime\uff1a\u8fd0\u884c\u65f6\u76ee\u5f55\uff0c\u5305\u62ec\u7f13\u5b58\u6587\u4ef6\u3001\u65e5\u5fd7\u6587\u4ef6\u7b49\u3002<\/li>\n<li>thinkphp\uff1aThinkPHP\u6846\u67b6\u7cfb\u7edf\u76ee\u5f55\uff0c\u5305\u62ec\u6838\u5fc3\u7c7b\u5e93\u3001\u51fd\u6570\u5e93\u7b49\u3002<\/li>\n<li>vendor\uff1aComposer\u7c7b\u5e93\u76ee\u5f55\uff0c\u5305\u62ecThinkPHP\u6269\u5c55\u7c7b\u5e93\u3001\u7b2c\u4e09\u65b9\u7c7b\u5e93\u7b49\u3002<\/li>\n<li>.htaccess\uff1ahtaccess\u6587\u4ef6\uff0c\u7528\u4e8eURL\u91cd\u5199\u3002<\/li>\n<li>composer.json\uff1aComposer\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8e\u5305\u7ba1\u7406\u3002<\/li>\n<li>README.md\uff1a\u6846\u67b6\u8bf4\u660e\u6587\u4ef6\u3002<\/li>\n<li>think\uff1a\u547d\u4ee4\u884c\u5165\u53e3\u6587\u4ef6\uff0c\u7528\u4e8e\u6267\u884c\u5404\u79cd\u547d\u4ee4\u3002<\/li>\n<\/ol>\n<p>\u4e09\u3001\u6570\u636e\u5e93\u914d\u7f6e<\/p>\n<p>\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\u5728ThinkPHPconfig\u76ee\u5f55\u4e0b\u7684database.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u914d\u7f6e\u91cc\u9762\u7684\u53c2\u6570\uff0c\u6bd4\u5982\u6570\u636e\u5e93\u4e3b\u673a\u5730\u5740\u3001\u6570\u636e\u5e93\u540d\u79f0\u3001\u6570\u636e\u5e93\u7528\u6237\u540d\u548c\u5bc6\u7801\u7b49\u3002<\/p>\n<p>\u5177\u4f53\u914d\u7f6e\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>return [\n    \/\/ \u6570\u636e\u5e93\u7c7b\u578b\n    'type'            =&gt; 'mysql',\n    \/\/ \u670d\u52a1\u5668\u5730\u5740\n    'hostname'        =&gt; 'localhost',\n    \/\/ \u6570\u636e\u5e93\u540d\n    'database'        =&gt; 'test',\n    \/\/ \u7528\u6237\u540d\n    'username'        =&gt; 'root',\n    \/\/ \u5bc6\u7801\n    'password'        =&gt; '',\n    \/\/ \u7aef\u53e3\n    'hostport'        =&gt; '',\n    \/\/ \u8fde\u63a5dsn\n    'dsn'             =&gt; '',\n    \/\/ \u6570\u636e\u5e93\u8fde\u63a5\u53c2\u6570\n    'params'          =&gt; [],\n    \/\/ \u6570\u636e\u5e93\u7f16\u7801\u9ed8\u8ba4\u91c7\u7528utf8\n    'charset'         =&gt; 'utf8',\n    \/\/ \u6570\u636e\u5e93\u8868\u524d\u7f00\n    'prefix'          =&gt; 'think_',\n    \/\/ \u6570\u636e\u5e93\u8c03\u8bd5\u6a21\u5f0f\n    'debug'           =&gt; true,\n    \/\/ \u5f00\u542f\u81ea\u52a8\u5199\u5165\u65f6\u95f4\u6233\u5b57\u6bb5\n    'auto_timestamp'  =&gt; true,\n    \/\/ \u5f00\u542f\u5b57\u6bb5\u7f13\u5b58\n    'fields_cache'    =&gt; true,\n];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u56db\u3001\u8def\u7531\u914d\u7f6e<\/p>\n<p>\u8def\u7531\u914d\u7f6e\u6587\u4ef6\u5728ThinkPHP oute\u76ee\u5f55\u4e0b\uff0c\u5982\u9700\u8981\u8bbe\u7f6eURL\u5730\u5740\u53d8\u91cf\uff0c\u5219\u9700\u8981\u4fee\u6539\u8be5\u76ee\u5f55\u4e0b\u7684route.php\u6587\u4ef6\uff0c\u5177\u4f53\u914d\u7f6e\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>use thinkRoute;\n\nRoute::get('hello\/:name', 'index\/hello');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u8868\u793a\u8bbe\u7f6e\u4e00\u4e2aget\u8bf7\u6c42\u7684\u8def\u7531\uff0c\u5f53\u7528\u6237\u8bbf\u95eehttp:\/\/\u4f60\u7684\u57df\u540d\/hello\/abc\u65f6\uff0c\u5c06\u4f1a\u6620\u5c04\u5230index\u63a7\u5236\u5668\u7684hello\u65b9\u6cd5\uff0c\u5e76\u5c06abc\u4f5c\u4e3a\u65b9\u6cd5\u7684\u53c2\u6570\u4f20\u5165\u3002<\/p>\n<p>\u4e94\u3001\u5e94\u7528\u914d\u7f6e<\/p>\n<p>\u5e94\u7528\u914d\u7f6e\u6587\u4ef6\u5728ThinkPHPconfig\u76ee\u5f55\u4e0b\u7684app.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8be5\u6587\u4ef6\u6765\u8bbe\u7f6e\u5e94\u7528\u7684\u914d\u7f6e\u53c2\u6570\uff0c\u6bd4\u5982\u9ed8\u8ba4\u7684\u63a7\u5236\u5668\u3001\u64cd\u4f5c\u65b9\u6cd5\u7b49\u3002<\/p>\n<p>\u5177\u4f53\u914d\u7f6e\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>return [\n    \/\/ \u9ed8\u8ba4\u63a7\u5236\u5668\u540d\n    'default_controller'    =&gt; 'Index',\n    \/\/ \u9ed8\u8ba4\u64cd\u4f5c\u540d\n    'default_action'        =&gt; 'index',\n    \/\/ \u5f02\u5e38\u5904\u7406handle\u7c7b \u7559\u7a7a\u4f7f\u7528 \thinkexceptionHandle\n    'exception_handle'      =&gt; '',\n];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u516d\u3001\u6a21\u677f\u914d\u7f6e<\/p>\n<p>\u6a21\u677f\u914d\u7f6e\u6587\u4ef6\u5728ThinkPHPconfig\u76ee\u5f55\u4e0b\u7684template.php\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8be5\u6587\u4ef6\u6765\u8bbe\u7f6e\u6a21\u677f\u5f15\u64ce\u7684\u53c2\u6570\uff0c\u6bd4\u5982\u8bbe\u7f6e\u6a21\u677f\u7684\u7f13\u5b58\u8def\u5f84\u3001\u6807\u7b7e\u8d77\u59cb\u6807\u8bb0\u3001\u6807\u7b7e\u7ed3\u675f\u6807\u8bb0\u7b49\u3002<\/p>\n<p>\u5177\u4f53\u914d\u7f6e\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>return [\n    \/\/ \u6a21\u677f\u6587\u4ef6\u76ee\u5f55\n    'view_path'    =&gt; '',\n    \/\/ \u6a21\u677f\u540e\u7f00\n    'view_suffix'  =&gt; 'html',\n    \/\/ \u6a21\u677f\u5f15\u64ce\u7c7b\u578b \u652f\u6301 php think \u652f\u6301\u6269\u5c55\n    'type'         =&gt; 'Think',\n    \/\/ \u6a21\u677f\u8def\u5f84\u66ff\u6362\n    'view_depr'    =&gt; DIRECTORY_SEPARATOR,\n    \/\/ \u6a21\u677f\u5f15\u64ce\u666e\u901a\u6807\u7b7e\u5f00\u59cb\u6807\u8bb0\n    'tpl_begin'    =&gt; '{',\n    \/\/ \u6a21\u677f\u5f15\u64ce\u666e\u901a\u6807\u7b7e\u7ed3\u675f\u6807\u8bb0\n    'tpl_end'      =&gt; '}',\n    \/\/ \u6807\u7b7e\u5e93\u6807\u7b7e\u5f00\u59cb\u6807\u8bb0\n    'taglib_begin' =&gt; '{',\n    \/\/ \u6807\u7b7e\u5e93\u6807\u7b7e\u7ed3\u675f\u6807\u8bb0\n    'taglib_end'   =&gt; '}',\n];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e03\u3001\u603b\u7ed3<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u914d\u7f6e\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u7075\u6d3b\u5730\u5b9e\u73b0\u5bf9ThinkPHP5\u6846\u67b6\u7684\u914d\u7f6e\uff0c\u4ece\u800c\u4f7f\u5176\u66f4\u597d\u5730\u6ee1\u8db3\u6211\u4eec\u7684\u9700\u6c42\u3002\u540c\u65f6\uff0c\u8fd9\u4e9b\u914d\u7f6e\u4e5f\u662f\u6211\u4eec\u5728\u5b9e\u9645\u9879\u76ee\u5f00\u53d1\u4e2d\u9700\u8981\u7ecf\u5e38\u7528\u5230\u7684\u6280\u672f\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fthinkphp5\u600e\u4e48\u914d\u7f6e\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\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cphp\u8bed\u8a00\u5df2\u7ecf\u6210\u4e3a\u4e86\u975e\u5e38\u6d41\u884c\u7684\u4e00\u79cdweb\u5f00\u53d1\u8bed\u8a00\uff0c\u800cthinkphp\u5219\u662fphp\u4e2d\u8f83\u4e3a\u4f18\u79c0\u7684\u4e00\u79cd\u5f00\u53d1\u6846\u67b6\u3002\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecdthinkphp5\u7684\u914d\u7f6e\uff0c\u5e2e\u52a9\u5927\u5bb6\u66f4\u597d\u5730\u4f7f\u7528\u8fd9\u6b3e\u6846\u67b6\u3002 \u4e00\u3001\u73af\u5883\u8981\u6c42 \u5728\u5f00\u59cb\u914d\u7f6e\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u73af\u5883\u8fdb\u884c\u4e00\u4e9b\u8981\u6c42\u3002ThinkPHP5\u9700\u8981PHP5.4\u53ca\u4ee5\u4e0a\u7248\u672c\u652f\u6301\uff0c\u5e76\u4e14\u9700\u8981MySQL 5.0\u53ca\u4ee5\u4e0a\u7248\u672c\u3002\u5982\u679c\u60a8\u7684\u670d\u52a1\u5668\u6ee1\u8db3\u8fd9\u4e9b\u6761\u4ef6\uff0c\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u914d\u7f6e\u8fd9\u4e2a\u6846\u67b6\u4e86\u3002 \u4e8c\u3001\u76ee\u5f55\u7ed3\u6784\u53ca\u6587\u4ef6\u7528\u9014 \u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0bThinkPHP5\u7684\u76ee\u5f55\u7ed3\u6784\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b ThinkPHP\u251c\u2500app &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u5e94\u7528\u76ee\u5f55\u2502 &nbsp;\u251c\u2500controller &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u63a7\u5236\u5668\u76ee\u5f55\u2502 &nbsp;\u251c\u2500model &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u6a21\u578b\u76ee\u5f55\u2502 &nbsp;\u2514\u2500view &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u89c6\u56fe\u76ee\u5f55\u251c\u2500config &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55\u251c\u2500public &nbsp; [&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-23727","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23727","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=23727"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/23727\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=23727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=23727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=23727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}