{"id":53145,"date":"2024-12-03T11:24:23","date_gmt":"2024-12-03T03:24:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53145\/"},"modified":"2024-12-03T11:24:23","modified_gmt":"2024-12-03T03:24:23","slug":"thinkphp-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e4%bc%9a%e5%91%98%e7%ad%89%e7%ba%a7%e5%b7%ae%e5%bc%82%e5%8c%96%e5%86%85%e5%ae%b9%e5%b1%95%e7%a4%ba%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53145\/","title":{"rendered":"ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f <\/h1>\n<p>\u5728\u6587\u7ae0\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f \u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17326872546746b59689a08.jpg\" class=\"aligncenter\" title=\"ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f\u63d2\u56fe\" alt=\"ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>ThinkPHP\u4e2d\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5c55\u793a<\/strong><\/p>\n<p>\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u8ba9\u4e0d\u540c\u4f1a\u5458\u7b49\u7ea7\u770b\u5230\u4e0d\u540c\u7684\u5185\u5bb9\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u5668\u548c\u89c6\u56fe\u6587\u4ef6\u7684\u7ed3\u5408\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002<\/p>\n<p><strong>1. \u63a7\u5236\u5668\u5904\u7406<\/strong><\/p>\n<p>\u5728\u63a7\u5236\u5668\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4f1a\u5458\u7b49\u7ea7\uff0c\u7136\u540e\u6839\u636e\u7b49\u7ea7\u51b3\u5b9a\u6e32\u67d3\u54ea\u4e2a\u89c6\u56fe\u6587\u4ef6\u3002<\/p>\n<pre>use think\\facade\\View;\nuse think\\facade\\Auth;\n\nclass Index\n{\n    public function index()\n    {\n        $user = Auth::user(); \/\/ \u83b7\u53d6\u5f53\u524d\u767b\u5f55\u7528\u6237\n        $level = $user['level']; \/\/ \u83b7\u53d6\u7528\u6237\u4f1a\u5458\u7b49\u7ea7\n        switch ($level) {\n            case 1:\n                return View::fetch('level1');\n            case 2:\n                return View::fetch('level2');\n            default:\n                return View::fetch('default');\n        }\n    }\n}<\/pre>\n<p><strong>2. \u89c6\u56fe\u6587\u4ef6\u5c55\u73b0<\/strong><\/p>\n<p>\u5728\u4e0d\u540c\u7684\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u73b0\u4e0d\u540c\u7684\u5185\u5bb9\u3002<\/p>\n<pre>&lt;!-- level1\u89c6\u56fe\u6587\u4ef6 --&gt;\n&lt;div&gt;\n    &lt;h1&gt;\u6b22\u8fce\u60a8\uff0c\u666e\u901a\u4f1a\u5458\uff01&lt;\/h1&gt;\n    &lt;p&gt;\u8fd9\u91cc\u662f\u666e\u901a\u4f1a\u5458\u80fd\u591f\u8bbf\u95ee\u7684\u5185\u5bb9\u3002&lt;\/p&gt;\n&lt;\/div&gt;\n\n&lt;!-- level2\u89c6\u56fe\u6587\u4ef6 --&gt;\n&lt;div&gt;\n    &lt;h1&gt;\u6b22\u8fce\u60a8\uff0c\u9ad8\u7ea7\u4f1a\u5458\uff01&lt;\/h1&gt;\n    &lt;p&gt;\u8fd9\u91cc\u662f\u9ad8\u7ea7\u4f1a\u5458\u80fd\u591f\u8bbf\u95ee\u7684\u5185\u5bb9\u3002&lt;\/p&gt;\n&lt;\/div&gt;\n\n&lt;!-- default\u89c6\u56fe\u6587\u4ef6 --&gt;\n&lt;div&gt;\n    &lt;h1&gt;\u8bf7\u5148\u767b\u5f55\uff01&lt;\/h1&gt;\n    &lt;p&gt;\u60a8\u8fd8\u672a\u767b\u5f55\uff0c\u8bf7\u5148\u767b\u5f55\u540e\u518d\u8fdb\u884c\u64cd\u4f5c\u3002&lt;\/p&gt;\n&lt;\/div&gt;<\/pre>\n<p>\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u8fd4\u56de\u6307\u5b9a\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u5373\u53ef\u5b9e\u73b0\u4f1a\u5458\u5dee\u5f02\u5316\u5c55\u793a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8981\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u9700\u6c42\u5b9a\u5236\u4e0d\u540c\u7684\u5185\u5bb9\u5c55\u793a\u3002\u540c\u65f6\uff0c\u4e3a\u4e86\u7cfb\u7edf\u5b89\u5168\uff0c\u5e94\u8fdb\u884c\u7528\u6237\u4f1a\u5458\u7b49\u7ea7\u9a8c\u8bc1\uff0c\u9632\u6b62\u975e\u6cd5\u8bbf\u95ee\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f \u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   Win11\u65e0\u6cd5\u6253\u5f00\u4efb\u4f55\u7b2c\u4e09\u65b9\u5e94\u7528\u600e\u4e48\u529e\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f \u5728\u6587\u7ae0\u5b9e\u6218\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u8fd9\u6837\u90a3\u6837\u7684\u95ee\u9898\uff0c\u7136\u540e\u8981\u5361\u597d\u534a\u5929\uff0c\u7b49\u95ee\u9898\u89e3\u51b3\u4e86\u624d\u53d1\u73b0\u539f\u6765\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u662f\u6ca1\u6709\u638c\u63e1\u597d\u3002\u4eca\u5929\u7c73\u4e91\u5c31\u6574\u7406\u5206\u4eab\u300aThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f \u300b\uff0c\u804a\u804a\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5230\u6b63\u5728\u52aa\u529b\u8d5a\u94b1\u7684\u4f60\u3002 ThinkPHP\u4e2d\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5c55\u793a \u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u8ba9\u4e0d\u540c\u4f1a\u5458\u7b49\u7ea7\u770b\u5230\u4e0d\u540c\u7684\u5185\u5bb9\u3002\u5728ThinkPHP\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u5668\u548c\u89c6\u56fe\u6587\u4ef6\u7684\u7ed3\u5408\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002 1. \u63a7\u5236\u5668\u5904\u7406 \u5728\u63a7\u5236\u5668\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4f1a\u5458\u7b49\u7ea7\uff0c\u7136\u540e\u6839\u636e\u7b49\u7ea7\u51b3\u5b9a\u6e32\u67d3\u54ea\u4e2a\u89c6\u56fe\u6587\u4ef6\u3002 use think\\facade\\View; use think\\facade\\Auth; class Index { public function index() { $user = Auth::user(); \/\/ \u83b7\u53d6\u5f53\u524d\u767b\u5f55\u7528\u6237 $level = $user[&#8216;level&#8217;]; \/\/ \u83b7\u53d6\u7528\u6237\u4f1a\u5458\u7b49\u7ea7 switch ($level) { case 1: return View::fetch(&#8216;level1&#8217;); case 2: return View::fetch(&#8216;level2&#8217;); default: return View::fetch(&#8216;default&#8217;); } } } 2. \u89c6\u56fe\u6587\u4ef6\u5c55\u73b0 \u5728\u4e0d\u540c\u7684\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u73b0\u4e0d\u540c\u7684\u5185\u5bb9\u3002 &lt;!&#8211; level1\u89c6\u56fe\u6587\u4ef6 &#8211;&gt; &lt;div&gt; [&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-53145","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53145","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=53145"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53145\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}