

{"id":247,"date":"2023-08-22T15:31:07","date_gmt":"2023-08-22T07:31:07","guid":{"rendered":"https:\/\/www.01j.top\/?p=247"},"modified":"2023-08-22T15:31:08","modified_gmt":"2023-08-22T07:31:08","slug":"thinkphp-6-%e5%ae%89%e8%a3%85%e3%80%81%e7%9f%ad%e7%bd%91%e5%9d%80%e8%b7%af%e7%94%b1%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.01j.top\/?p=247","title":{"rendered":"ThinkPHP 6 \u5b89\u88c5\u3001\u77ed\u7f51\u5740\u8def\u7531\u914d\u7f6e"},"content":{"rendered":"\n<p>\u63a8\u8350\u4f7f\u7528\u5b98\u65b9\u7684TP6\u624b\u518c\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"978\" height=\"354\" src=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image.png\" alt=\"\" class=\"wp-image-248\" srcset=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image.png 978w, https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-300x109.png 300w, https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-768x278.png 768w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.kancloud.cn\/manual\/thinkphp6_0\/1037479\">https:\/\/www.kancloud.cn\/manual\/thinkphp6_0\/1037479<\/a><\/p>\n\n\n\n<h2 id=\"h2-0\">\u4e00\u3001TP6\u5b89\u88c5<\/h2>\n\n\n\n<p>1\u3001Windows\u7cfb\u7edf\u5b89\u88c5composer\u00a0<a href=\"https:\/\/pkg.phpcomposer.com\/#how-to-install-composer\">\u00a0 https:\/\/pkg.phpcomposer.com\/#how-to-install-composer<\/a><\/p>\n\n\n\n<p>2\u3001\u4f7f\u7528composer\u5b89\u88c5ThinkPHP\uff0c\uff1a<\/p>\n\n\n\n<p><code>composer create-project topthink\/think tp<\/code><\/p>\n\n\n\n<p>3\u3001web\u670d\u52a1\u5668\u8bbe\u7f6e\u8bbf\u95eetp6\u6839\u76ee\u5f55\u4e0b\u7684public\u76ee\u5f55\u5373\u53ef<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"656\" height=\"383\" src=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-1.png\" alt=\"\" class=\"wp-image-249\" srcset=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-1.png 656w, https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-1-300x175.png 300w\" sizes=\"(max-width: 656px) 100vw, 656px\" \/><\/figure>\n\n\n\n<h2 id=\"h2-1\">\u4e8c\u3001\u67e5\u770bTP6\u7684\u7248\u672c<\/h2>\n\n\n\n<p><code>cd \/D\/www\/tp6.com\/<br>php think version<br>\u663e\u793av6.0.9<\/code><\/p>\n\n\n\n<h2 id=\"h2-2\">\u4e09\u3001TP6\u9690\u85cfindex.php<\/h2>\n\n\n\n<p><strong>1.Nginx<\/strong>&nbsp;\u8bbe\u7f6eweb\u670d\u52a1\u5668Nginx\u7684\u4f2a\u9759\u6001\u4e3a<\/p>\n\n\n\n<p><code>location \/ {<br>\u00a0 if (!-e $request_filename){<br>\u00a0 \u00a0 rewrite ^(.*)$ \/index.php?s=$1 last; break;<br>\u00a0 }<br>}<\/code><\/p>\n\n\n\n<p><strong>2.Apache<\/strong><br>\u4fee\u6539\/public\/.htaccess\u6587\u4ef6\uff0c\u627e\u5230\uff1a<br>RewriteRule ^(.<em>)$ index.php\/$1 [QSA,PT,L] \u5728index.php\u540e\u9762<strong>\u52a0\u4e00\u4e2a\u95ee\u53f7<\/strong>\uff0c\u53d8\u6210\uff1a RewriteRule ^(.<\/em>)$ index.php?\/$1 [QSA,PT,L]<\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<h2 id=\"h2-3\">\u56db\u3001TP6\u5f00\u542f\u591a\u5e94\u7528<\/h2>\n\n\n\n<p><br>cd \/D\/www\/tp6.com\/<br><code>rm -R app\/* [\u5220\u6389\u6839\u76ee\u5f55\u4e0b\u7684app\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6]<br>composer require topthink\/think-multi-app<br>php think build {Name-of-APP-1}<br>php think build {Name-of-APP-2}<\/code><br>\u4fee\u6539\/config\/app.php\u7684\u201cdefault_app\u201d\u4e3a\u81ea\u5efa\u7684app\u540d\u79f0<br><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"774\" height=\"401\" src=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-2.png\" alt=\"\" class=\"wp-image-250\" srcset=\"https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-2.png 774w, https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-2-300x155.png 300w, https:\/\/www.01j.top\/wp-content\/uploads\/2023\/08\/image-2-768x398.png 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<h2 id=\"h2-4\">\u4e94\u3001TP6\u66ff\u6362admin\u7b49app\u540d\u5b57<\/h2>\n\n\n\n<p><br>\u4fee\u6539\/config\/app.php\uff0c\u4fee\u6539\u5e94\u7528\u6620\u5c04\uff1a<\/p>\n\n\n\n<p>\/\/ \u5e94\u7528\u6620\u5c04\uff08\u81ea\u52a8\u591a\u5e94\u7528\u6a21\u5f0f\u6709\u6548\uff09<br><code>'app_map' => ['backend' => 'admin'],<\/code><\/p>\n\n\n\n<p>\u8fd9\u6837\uff0cbackend\u5c31\u4f1a\u66ff\u4ee3admin<\/p>\n\n\n\n<h2 id=\"h2-5\">\u516d\u3001TP6\u77ed\u7f51\u5740\u8def\u7531\u914d\u7f6e\uff08\u540c\u4e00\u4e2aapp\u4e0b\uff0c\u7f29\u77ed\u7f51\u5740\uff09<\/h2>\n\n\n\n<p><br>\u77ed\u7f51\u5740 \u5b9e\u9645\u7f51\u5740 \u6b65\u9aa4<br>1 tp6.com\/<br>tp6.com\/home\/index\/showHome\/<\/p>\n\n\n\n<p>1.\u589e\u52a0app\\home\\controller\\Index.php\u4e00\u4e2a\u65b0\u65b9\u6cd5<br>public function ShowHome()<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    return 'home page from http:\/\/tp6.com\/';\n\n}<\/code><\/pre>\n\n\n\n<ol start=\"2\"><li>\u65b0\u589eroute\u6587\u4ef6app\\home\\route\\any-name.php\uff0c\u5185\u5bb9\u4e3a<\/li><\/ol>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>use think\\facade\\Route;<\/p>\n\n\n\n<p>Route::get(&#8216;\/&#8217;, &#8216;home\/index\/showHome&#8217;);<\/p>\n\n\n\n<p>2 tp6.com\/backend tp6.com\/admin\/ \/config\/app.php\uff0c\u4fee\u6539\u5e94\u7528\u6620\u5c04<br>3 tp6.com\/home\/plus tp6.com\/home\/student\/plus<br>\u590d\u5236\u63a7\u5236\u5668app\\home\\controller\\Index.php\u4e3aapp\\home\\controller\\Student.php\uff0c\u4fee\u6539class\u540d\u4e3aStudent<br>\u4e3a\u521a\u624d\u7684\u63a7\u5236\u5668\u589e\u52a0\u4e00\u4e2a\u65b9\u6cd5<br>public function plus () {<br>return $_SERVER[&#8216;REQUEST_URI&#8217;];<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u65b0\u589eroute\u6587\u4ef6app\\home\\route\\hahaha.php\uff0c\u5185\u5bb9\u589e\u52a0Route::get(&#8216;plus&#8217;, &#8216;home\/student\/plus&#8217;);<br>4 tp6.com\/news tp6.com\/home\/index\/news \u8fd9\u4e2a\u5f88\u96be\uff0c\u56e0\u4e3a\u591a\u5e94\u7528\u4e0broute\u8def\u7531\u8bbe\u7f6e\u6bd4\u8f83\u5bb9\u6613\u4e71\uff0c\u5177\u4f53\u8bf7\u770b\u672c\u6587\u7684\u6700\u4e0b\u9762\u90e8\u5206\u201c\u591a\u5e94\u7528\u4e0b\u5355\u53c2\u6570\u8def\u7531\u201d<br>\u7279\u522b\u6ce8\u610f<br>\u6700\u597d\u63a7\u5236\u5668\u91cc\u9762\u65b9\u6cd5\u540d\u5b57 \u90fd\u662f\u5927\u5199\u5b57\u6bcd\u5f00\u5934\uff0c\u4e0d\u7136\u597d\u591a\u5947\u5947\u602a\u602a\u7684\u95ee\u9898\uff01<br>\u5173\u4e8eroute\u914d\u7f6e\u6587\u4ef6\uff0c<br>1\uff09\u5982\u679c\u662f\u5355\u5e94\u7528\u6a21\u5f0f\uff0c\u53ea\u9700\u4fee\u6539\/route\/*.php\uff0c\u540d\u5b57\u968f\u610f\uff0c\u6587\u4ef6\u6570\u91cf\u968f\u610f\uff0c\u53cd\u6b63\u90fd\u8bfb\u53d6\uff1b<br>2\uff09\u5982\u679c\u662f\u591a\u5e94\u7528\u6a21\u5f0f\uff0c\u9700\u8981\u5404\u81ea\u5728\u4e0d\u540c\u7684\u5e94\u7528\u76ee\u5f55\u4e0b\u521b\u5efaroute\u76ee\u5f55\uff0c\u91cc\u9762\u7684route\u914d\u7f6e\u6587\u4ef6\u540d\u5b57\u968f\u610f\uff0c\u683c\u5f0f\u4e3aphp\uff0c\u4f8b\u5982\uff1a<br>\/app\/home\/route\/home.php<br>\/app\/book\/route\/any.php<br>\/app\/book\/route\/222.php<\/p>\n\n\n\n<p>\u683c\u5f0f<br>&lt;?php<br>use think\\facade\\Route;<br>Route::get(&#8216;\/&#8217;, function(){<br>return &#8216;Catched route &#8220;\/&#8221;&#8216;;<br>});<\/p>\n\n\n\n<p>Route::get(&#8216;plus&#8217;, &#8216;home\/student\/plus&#8217;);<br>TP6\u591a\u5e94\u7528\u4e0b\u5355\u53c2\u6570\u8def\u7531<br>\u76ee\u6807\uff1a<\/p>\n\n\n\n<p>http:\/\/tp6.com\/news<\/p>\n\n\n\n<p>\u53ef\u4ee5\u8bbf\u95ee\u5230<\/p>\n\n\n\n<p>http:\/\/tp6.com\/home\/ccc\/news<\/p>\n\n\n\n<p>\u6b65\u9aa4<br>\u590d\u5236\u63a7\u5236\u5668app\\home\\controller\\Index.php\u4e3aapp\\home\\controller\\Ccc.php<br>\u4fee\u6539Ccc.php\u7684\u7c7b\u540d\u4e3aCcc<br>\u5728Ccc.php\u4e2d\u7c7bCcc\u91cc\u9762\u65b0\u589e\u65b9\u6cd5news()\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<br>&lt;?php<br>declare (strict_types = 1);<br>namespace app\\home\\controller;<\/p>\n\n\n\n<p>class Ccc<br>{<br>public function News () {<br>return <strong>FILE<\/strong> . &#8216; [line] &#8216;.<strong>LINE<\/strong> . &#8216; [FN] &#8216;.<strong>FUNCTION<\/strong>;<br>}<br>}<br>\u786e\u8ba4http:\/\/tp6.com\/home\/ccc\/news\u53ef\u4ee5\u8bbf\u95ee<br>\u914d\u7f6e\u8def\u7531\u6587\u4ef6app\\home\\route\\home2.php\uff0c\u4fee\u6539\u4e3a<br>run();&#8221;\u4fee\u6539\u4e3a<br>if (preg_match(&#8216;\/^\\\/(common|admin|backend)\\\/\/&#8217;, $_SERVER[&#8216;REQUEST_URI&#8217;])) {<br>$response = $http-&gt;run();<br>} else {<br>$response = $http-&gt;name(&#8216;home&#8217;)-&gt;run();<br>}<br>\u5176\u4e2d\uff0c\u201ccommon|admin|backend\u201d\u662f\u9664\u53bb\u5f53\u524d\u5f3a\u5236\u7684app\u4ee5\u5916\u7684\u6a21\u5757\u540d\u5b57\uff0c\u8fd9\u6837\u5176\u4ed6app\u5c31\u4e0d\u4f1a\u88ab\u5f53\u524d\u8def\u7531\u8bbe\u7f6e\u5f71\u54cd\u5230\u3002<\/p>\n\n\n\n<p>ok\uff0c\u6d4b\u8bd5\uff01<br>\u6ca1\u95ee\u9898<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a8\u8350\u4f7f\u7528\u5b98\u65b9\u7684TP6\u624b\u518c\u00a0 https:\/\/www.kancloud.cn\/manual\/thinkphp6_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/247"}],"collection":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=247"}],"version-history":[{"count":1,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":251,"href":"https:\/\/www.01j.top\/index.php?rest_route=\/wp\/v2\/posts\/247\/revisions\/251"}],"wp:attachment":[{"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.01j.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}