{"id":2590,"date":"2024-11-10T12:35:34","date_gmt":"2024-11-10T04:35:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2590\/"},"modified":"2024-11-10T12:35:34","modified_gmt":"2024-11-10T04:35:34","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","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2590\/","title":{"rendered":"ThinkPHP \u5982\u4f55\u5b9e\u73b0\u4f1a\u5458\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173080656351486.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>\u4e2d\u5b9e\u73b0\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 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        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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u89c6\u56fe\u6587\u4ef6\u5c55\u73b0<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fThinkPHP \u5982\u4f55\u5b9e\u73b0\u7b49\u7ea7\u5dee\u5f02\u5316\u5185\u5bb9\u5c55\u793a\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>\u4e2d\u5b9e\u73b0\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 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 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;); } } } \u767b\u5f55\u540e\u590d\u5236 2. \u89c6\u56fe\u6587\u4ef6\u5c55\u73b0 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \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; &lt;h1&gt;\u6b22\u8fce\u60a8\uff0c\u666e\u901a\u4f1a\u5458\uff01&lt;\/h1&gt; &lt;p&gt;\u8fd9\u91cc\u662f\u666e\u901a\u4f1a\u5458\u80fd\u591f\u8bbf\u95ee\u7684\u5185\u5bb9\u3002&lt;\/p&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-2590","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2590","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=2590"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2590\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}