{"id":26289,"date":"2024-11-24T08:59:51","date_gmt":"2024-11-24T00:59:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26289\/"},"modified":"2024-11-24T08:59:51","modified_gmt":"2024-11-24T00:59:51","slug":"thinkphp%ef%bc%9a%e5%a6%82%e4%bd%95%e6%a0%b9%e6%8d%ae%e4%bc%9a%e5%91%98%e7%ad%89%e7%ba%a7%e5%b1%95%e7%a4%ba%e4%b8%93%e5%b1%9e%e5%86%85%e5%ae%b9%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26289\/","title":{"rendered":"ThinkPHP\uff1a\u5982\u4f55\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u793a\u4e13\u5c5e\u5185\u5bb9\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173087785271912.jpg\" class=\"aligncenter\" title=\"ThinkPHP\uff1a\u5982\u4f55\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u793a\u4e13\u5c5e\u5185\u5bb9\uff1f\u63d2\u56fe\" alt=\"ThinkPHP\uff1a\u5982\u4f55\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u793a\u4e13\u5c5e\u5185\u5bb9\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\uff1a\u4e0d\u540c\u7b49\u7ea7\u5c55\u73b0\u4e13\u5c5e\u5185\u5bb9<\/strong><\/p>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u6839\u636e\u7528\u6237\u7684\u4e0d\u540c\u4f1a\u5458\u7b49\u7ea7\u5c55\u793a\u4e0d\u540c\u7684\u5185\u5bb9\uff0cThinkPHP\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65b9\u5f0f\u5b9e\u73b0\u8fd9\u4e00\u9700\u6c42\u3002<\/p>\n<p>\u9996\u5148\uff0c\u5728\u63a7\u5236\u5668\u4e2d\u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4f1a\u5458\u7b49\u7ea7\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>use thinkacadeView;\nuse thinkacadeAuth;\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        ...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u6839\u636e\u4e0d\u540c\u7684\u4f1a\u5458\u7b49\u7ea7\u52a0\u8f7d\u4e0d\u540c\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>...\nif ($level == 1) {\n    return View::fetch('level1');\n} elseif ($level == 2) {\n    return View::fetch('level2');\n} else {\n    return View::fetch('default');\n}\n...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u73b0\u4e0d\u540c\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u4e0d\u540c\u4f1a\u5458\u7b49\u7ea7\u7684\u7528\u6237\u53ef\u4ee5\u770b\u5230\u4e13\u5c5e\u7684\u5185\u5bb9\uff0c\u6ee1\u8db3\u4e0d\u540c\u7528\u6237\u7684\u4e2a\u6027\u5316\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP\uff1a\u5982\u4f55\u6839\u636e\u7b49\u7ea7\u5c55\u793a\u4e13\u5c5e\u5185\u5bb9\uff1f\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>\uff1a\u4e0d\u540c\u7b49\u7ea7\u5c55\u73b0\u4e13\u5c5e\u5185\u5bb9 \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5e38\u5e38\u9700\u8981\u6839\u636e\u7528\u6237\u7684\u4e0d\u540c\u4f1a\u5458\u7b49\u7ea7\u5c55\u793a\u4e0d\u540c\u7684\u5185\u5bb9\uff0cThinkPHP\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65b9\u5f0f\u5b9e\u73b0\u8fd9\u4e00\u9700\u6c42\u3002 \u9996\u5148\uff0c\u5728\u63a7\u5236\u5668\u4e2d\u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4f1a\u5458\u7b49\u7ea7\uff0c\u4f8b\u5982\uff1a use thinkacadeView; use thinkacadeAuth; 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 &#8230; } } \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u6839\u636e\u4e0d\u540c\u7684\u4f1a\u5458\u7b49\u7ea7\u52a0\u8f7d\u4e0d\u540c\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a &#8230; if ($level == 1) { return View::fetch(&#8216;level1&#8217;); } elseif ($level == 2) { return View::fetch(&#8216;level2&#8217;); } else { return View::fetch(&#8216;default&#8217;); } &#8230; \u767b\u5f55\u540e\u590d\u5236 \u5728\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6839\u636e\u4f1a\u5458\u7b49\u7ea7\u5c55\u73b0\u4e0d\u540c\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b [&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-26289","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26289","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=26289"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26289\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}