{"id":475,"date":"2021-06-29T17:45:05","date_gmt":"2021-06-29T09:45:05","guid":{"rendered":"http:\/\/blog.doublejia.cn\/?p=475"},"modified":"2021-08-20T16:14:37","modified_gmt":"2021-08-20T08:14:37","slug":"tp6-%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/blog.doublejia.cn\/?p=475","title":{"rendered":"TP6 \u5b66\u4e60"},"content":{"rendered":"\n<p>\u5b89\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">composer create-project topthink\/think .<\/pre>\n\n\n\n<p>\u5b89\u88c5\u591a\u5e94\u7528\u7ec4\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">composer require topthink\/think-multi-app\ncomposer require topthink\/think-view<\/pre>\n\n\n\n<p>\u9047\u5230\u95ee\u9898#1\uff0c<br>\u60f3\u628a\u5e94\u7528\u76ee\u5f55\u548cvendor \u653e\u5230\u4e0d\u540c\u7684\u6587\u4ef6\u5939\u4e2d\u3002<br>App \u7684 thinkPath \/ rootPath \/ appPath \/ runtimePath \u3002 \u9700\u8981\u91cd\u65b0\u60f3\u4e00\u60f3\u4e86.....<br> <br>\u57286.0.7 \u7248\u672c\u4e2d\uff0c\u6709\u4e0d\u5c11\u4ee3\u7801\u91cc\uff0c\u7528\u7684\u662f  app()-&gt;getRootPah() . 'app'   \u6216\u8005  app()-&gt;getRootPath() . 'vendor'  \u8fd9\u79cd\u65b9\u6cd5\uff0c\u6240\u4ee5\u6ca1\u6709\u529e\u6cd5\u76f4\u63a5\u89e3\u51b3\u3002 <\/p>\n\n\n\n<p>\u89e3\u51b3\u95ee\u9898#1<br>\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u5e94\u8be5\u662f\u53ef\u4ee5\u89e3\u51b3\u7edd\u5927\u90e8\u5206\u95ee\u9898\uff0c\u8fd8\u5728\u6301\u7eed\u89c2\u5bdf\u4e2d\u3002<br>\u5728 App.php \u4e2d\uff0c\u52a0\u5165 $appRootPath<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function __construct(string $rootPath = '', string $appRootPath = '') \/\/ \u589e\u52a0 $appRootPath\n{\n    $this-&gt;thinkPath   = dirname(__DIR__) . DIRECTORY_SEPARATOR;\n    $this-&gt;rootPath    = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this-&gt;getDefaultRootPath();\n    $this-&gt;appRootPath = empty($appRootPath) ? $this-&gt;rootPath : $appRootPath . DIRECTORY_SEPARATOR; \/\/ \u589e\u52a0\u7684\u90e8\u5206\n    $this-&gt;appPath     = $this-&gt;appRootPath . 'app' . DIRECTORY_SEPARATOR;  \/\/ \u4fee\u6539\u7684\u90e8\u5206\n    $this-&gt;runtimePath = $this-&gt;appRootPath . 'runtime' . DIRECTORY_SEPARATOR;  \/\/ \u4fee\u6539\u7684\u90e8\u5206\n    \/\/ ......... Other codes\n}\n\npublic function getAppRootPath(): string  \/\/ \u589e\u52a0\u7684\u65b9\u6cd5\n{\n    return $this-&gt;appRootPath;\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u65b0\u5165\u53e3\u6587\u4ef6\u4e2d\uff0c\u589e\u52a0\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>namespace think;\n$loader = include_once '\/thinkphp\/v6\/vendor\/autoload.php';\n$loader-&gt;setPsr4('app\\\\', [__DIR__.'\\\\app\\\\']);  \/\/ \u91cd\u5199classloader\u65f6 app \u76ee\u5f55\u6240\u5728\u76ee\u5f55\u3002\n\n\/\/ \u6267\u884cHTTP\u5e94\u7528\u5e76\u54cd\u5e94\n$app = new App('', __DIR__); \/\/ \u589e\u52a0 $appRootPath \n\n$http = ($app)-&gt;http;\n\n$response = $http-&gt;run();\n\n$response-&gt;send();\n\n$http-&gt;end($response);<\/code><\/pre>\n\n\n\n<p>\u5728\u90e8\u5206\u4f7f\u7528 app \u7684\u76ee\u5f55\u90e8\u5206\uff0c\u628a app()-&gt; getRootPah() \u6539\u6210 app()-&gt;getAppRootPath()\u3002\u8fd9\u91cc\uff0c\u6211\u53eacomposer \u4e86 think-multi-app \/ think-view \u6240\u4ee5\u53ea\u5305\u62ec\u4e0b\u9762\uff1a<\/p>\n\n\n\n<ul><li>\/vendor\/topthink\/framework\/src\/helper.php    (line 635)<\/li><li>\/vendor\/topthink\/framework\/src\/Http.php (line 61 \/ 224)<\/li><li>\/vendor\/topthink\/framework\/src\/think\/console\/command\/Clear.php (line 34)<\/li><li>\/vendor\/topthink\/framework\/src\/think\/console\/command\/RouteList.php (line 45 \/ 63 \/ 65)<\/li><li>\/vendor\/topthink\/framework\/src\/think\/console\/command\/RunServer.php (line 55)<\/li><li>\/vendor\/topthink\/framework\/src\/think\/console\/command\/optimize\/Route.php (line 32 \/ 49)<\/li><li>\/vendor\/topthink\/framework\/src\/think\/view\/driver\/Php.php (line 131)<\/li><li>\/vendor\/topthink\/think-multi-app\/src\/command\/Clear.php (line 35)<\/li><\/ul>\n\n\n\n<p>\u89e3\u51b3\u95ee\u9898#2<br>\u5728\u4f7f\u7528vue element-plus-admin + tp6 \u65f6\uff0c\u9a8c\u8bc1\u7801\u90e8\u5206\u662f\u8de8\u57df\u7684\uff0c\u6d4f\u89c8\u5668\u4e0d\u4f1a\u4f20\u9012Cookie\uff0c\u9020\u6210session\u65e0\u6cd5\u4f7f\u7528\u3002<\/p>\n\n\n\n<ol><li>\u5728\u4e2d\u95f4\u4ef6\u4e2d\u589e\u52a0\uff0cAllowCrossDomain \u548c SeesionInit<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>return &#091;\n    \\think\\middleware\\AllowCrossDomain::class, \/\/ \u517c\u5bb9\u8de8\u57df\n    \\think\\middleware\\SessionInit::class \/\/ \u9a8c\u8bc1\u7801\u9700\u8981\u542f\u7528session\n];<\/code><\/pre>\n\n\n\n<p>2. \u4f7f\u7528 request \u6765\u4ee3\u66ffcookie\uff0c\u6765\u4f20\u9012session_id\u3002<br>\u5728config\\session.php \u4e2d\u4fee\u6539 var_session_id \u7684\u503c\u5230 uuid\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'var_session_id' =&gt; 'uuid',<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u8fd9\u91cc uuid \u7684\u683c\u5f0f\u4e3a  xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\uff0c\u9700\u8981\u4fee\u6539 think\\session\\Store::setId \u65b9\u6cd5\u4e3a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$this-&gt;id = is_string($id) &amp;&amp; ((strlen($id) === 32 &amp;&amp; ctype_alnum($id)) ||  \\preg_match('\/&#091;a-z0-9]{8}(-&#091;a-z0-9]{4}){3}-&#091;a-z0-9]{12}\/', $id, $mat)) ?  $id  : md5(microtime(true) . session_create_id());<\/code><\/pre>\n\n\n\n<p>PS\uff1a\u8fd9\u91cc\uff0c\u5e94\u8be5\u4e5f\u53ef\u4ee5\u5728\u4e2d\u95f4\u4ef6\u4e2d\u5148\u884c\u52a0\u5bc6\uff0c\u4f46\u539f\u56e0\u8fd9\u91cc\u7684 request \u662f\u6ca1\u529e\u6cd5\u4fee\u6539\u7684\uff0c\u6682\u65f6\u8fd8\u6ca1\u627e\u5230\u4e00\u4e2a\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u5c31\u76f4\u63a5\u4fee\u6539 seesion_id \u5141\u8bb8\u7684\u683c\u5f0f\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5 composer create-project topthink\/think . \u5b89\u88c5\u591a\u5e94\u7528\u7ec4\u4ef6 composer require topthink\/think-multi-app composer require topthink\/think-view \u9047\u5230\u95ee\u9898#1\uff0c\u60f3\u628a\u5e94\u7528\u76ee\u5f55\u548cvendor \u653e\u5230\u4e0d\u540c\u7684\u6587\u4ef6\u5939\u4e2d\u3002App \u7684 thinkPath \/ rootPath \/ appPath \/\u2026<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/posts\/475"}],"collection":[{"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=475"}],"version-history":[{"count":7,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.doublejia.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}