{"id":22914,"date":"2024-11-21T11:19:18","date_gmt":"2024-11-21T03:19:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22914\/"},"modified":"2024-11-21T11:19:18","modified_gmt":"2024-11-21T03:19:18","slug":"%e6%80%8e%e4%b9%88%e5%85%b3%e9%97%adthinkphp%e7%9a%84%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22914\/","title":{"rendered":"\u600e\u4e48\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55"},"content":{"rendered":"<\/p>\n<p><strong>ThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/p>\n<p>\u6211\u4eec\u9996\u5148\u6765\u4e86\u89e3\u4e00\u4e0bThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u3002\u5728ThinkPHP\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u5206\u4e3a\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u548c\u8fd0\u884c\u65f6\u65e5\u5fd7\u4e24\u79cd\u7c7b\u578b\u3002\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u662f\u7531\u5f00\u53d1\u4eba\u5458\u624b\u52a8\u8bb0\u5f55\u7684\u65e5\u5fd7\uff0c\u7528\u4e8e\u8c03\u8bd5\u548c\u6027\u80fd\u5206\u6790\u3002\u5b83\u80fd\u591f\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u591a\u79cd\u4fe1\u606f\uff0c\u5305\u62ec\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6267\u884c\u65f6\u95f4\u3001\u54cd\u5e94\u65f6\u95f4\u7b49\u3002\u5e94\u7528\u7a0b\u5e8f\u81ea\u52a8\u751f\u6210\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u53eb\u505a\u8fd0\u884c\u65f6\u65e5\u5fd7\uff0c\u5b83\u5e38\u7528\u4e8e\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u53d1\u751f\u7684\u5f02\u5e38\u548c\u9519\u8bef\u3002<\/p>\n<p>\u5728ThinkPHP\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u901a\u8fc7Monolog\u5e93\u5b9e\u73b0\u7684\u3002\u8bb8\u591aPHP\u5e94\u7528\u7a0b\u5e8f\u90fd\u4f7f\u7528Monolog\u8fd9\u4e2a\u53d7\u6b22\u8fce\u7684\u65e5\u5fd7\u5e93\u3002\u4f7f\u7528Monolog\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5404\u79cd\u5904\u7406\u7a0b\u5e8f\u548c\u683c\u5f0f\u5668\u6765\u81ea\u7531\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cThinkPHP\u4f1a\u81ea\u52a8\u52a0\u8f7dMonolog\u5e93\uff0c\u5e76\u4f7f\u7528\u9884\u8bbe\u7684\u914d\u7f6e\u3002\u8fd9\u610f\u5473\u7740\u5e94\u7528\u7a0b\u5e8f\u4f1a\u8bb0\u5f55\u6240\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u548c\u8fd0\u884c\u65f6\u65e5\u5fd7\u3002<\/p>\n<p><strong>\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u4e3a\u4e86\u589e\u5f3a\u6027\u80fd\u548c\u5b89\u5168\u6027\uff0c\u6216\u8bb8\u9700\u7981\u7528\u65e5\u5fd7\u8bb0\u5f55\u3002\u7981\u7528\u65e5\u5fd7\u8bb0\u5f55\u53ef\u4ee5\u51cf\u8f7b\u5e94\u7528\u7a0b\u5e8f\u7684\u8d1f\u8377\uff0c\u540c\u65f6\u589e\u5f3a\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7config.php\u6587\u4ef6\u7684\u914d\u7f6e\u6765\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u5404\u79cd\u914d\u7f6e\u9009\u9879\u90fd\u5305\u542b\u5728config.php\u4e2d\uff0c\u8fd9\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u5728config.php\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u662f\u53ef\u884c\u7684<\/p>\n<p>&#8216;log&#8217; =&gt; [<\/p>\n<pre>'type'&nbsp;=&amp;gt;&nbsp;'test'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>]<\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u628a\u952e\u540d\u4e3a&#8221;log&#8221;\u7684\u952e\u8bbe\u7f6e\u4e3a&#8221;value&#8221;\u3002\u8fd9\u610f\u5473\u7740\u5e94\u7528\u7a0b\u5e8f\u5c06\u4e0d\u4f1a\u8bb0\u5f55\u4efb\u4f55\u65e5\u5fd7\uff0c\u800c\u662f\u53ea\u8bb0\u5f55\u4e00\u4e2a\u6d4b\u8bd5\u503c\u3002\u91c7\u7528\u8fd9\u79cd\u505a\u6cd5\u53ef\u4ee5\u907f\u514d\u5728\u5199\u65e5\u5fd7\u65f6\u8017\u8d39\u65f6\u95f4\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002\u5f53\u7136\uff0c\u5982\u679c\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06&#8217;test&#8217;\u952e\u7684\u503c\u8bbe\u7f6e\u4e3a&#8217;file&#8217;\uff0c\u6765\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u8bb0\u5f55\uff0c\u65b9\u4fbf\u6392\u67e5\u95ee\u9898\u3002<\/p>\n<p>\u5728\u5173\u95ed\u65e5\u5fd7\u8bb0\u5f55\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528ThinkPHP\u63d0\u4f9b\u7684getError()\u65b9\u6cd5\u6765\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u629b\u51fa\u7684\u5f02\u5e38\u548c\u9519\u8bef\u3002\u901a\u8fc7\u4f7f\u7528getError()\u65b9\u6cd5\uff0c\u6211\u4eec\u80fd\u591f\u5feb\u901f\u5730\u8bc6\u522b\u95ee\u9898\u5e76\u8fc5\u901f\u89e3\u51b3\u5b83\u4eec\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\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>ThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55 \u6211\u4eec\u9996\u5148\u6765\u4e86\u89e3\u4e00\u4e0bThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u3002\u5728ThinkPHP\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u5206\u4e3a\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u548c\u8fd0\u884c\u65f6\u65e5\u5fd7\u4e24\u79cd\u7c7b\u578b\u3002\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u662f\u7531\u5f00\u53d1\u4eba\u5458\u624b\u52a8\u8bb0\u5f55\u7684\u65e5\u5fd7\uff0c\u7528\u4e8e\u8c03\u8bd5\u548c\u6027\u80fd\u5206\u6790\u3002\u5b83\u80fd\u591f\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\u7684\u591a\u79cd\u4fe1\u606f\uff0c\u5305\u62ec\u6570\u636e\u5e93\u67e5\u8be2\u3001\u6267\u884c\u65f6\u95f4\u3001\u54cd\u5e94\u65f6\u95f4\u7b49\u3002\u5e94\u7528\u7a0b\u5e8f\u81ea\u52a8\u751f\u6210\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u53eb\u505a\u8fd0\u884c\u65f6\u65e5\u5fd7\uff0c\u5b83\u5e38\u7528\u4e8e\u8bb0\u5f55\u5e94\u7528\u7a0b\u5e8f\u53d1\u751f\u7684\u5f02\u5e38\u548c\u9519\u8bef\u3002 \u5728ThinkPHP\u4e2d\uff0c\u65e5\u5fd7\u8bb0\u5f55\u662f\u901a\u8fc7Monolog\u5e93\u5b9e\u73b0\u7684\u3002\u8bb8\u591aPHP\u5e94\u7528\u7a0b\u5e8f\u90fd\u4f7f\u7528Monolog\u8fd9\u4e2a\u53d7\u6b22\u8fce\u7684\u65e5\u5fd7\u5e93\u3002\u4f7f\u7528Monolog\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u5404\u79cd\u5904\u7406\u7a0b\u5e8f\u548c\u683c\u5f0f\u5668\u6765\u81ea\u7531\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cThinkPHP\u4f1a\u81ea\u52a8\u52a0\u8f7dMonolog\u5e93\uff0c\u5e76\u4f7f\u7528\u9884\u8bbe\u7684\u914d\u7f6e\u3002\u8fd9\u610f\u5473\u7740\u5e94\u7528\u7a0b\u5e8f\u4f1a\u8bb0\u5f55\u6240\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u65e5\u5fd7\u548c\u8fd0\u884c\u65f6\u65e5\u5fd7\u3002 \u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u4e3a\u4e86\u589e\u5f3a\u6027\u80fd\u548c\u5b89\u5168\u6027\uff0c\u6216\u8bb8\u9700\u7981\u7528\u65e5\u5fd7\u8bb0\u5f55\u3002\u7981\u7528\u65e5\u5fd7\u8bb0\u5f55\u53ef\u4ee5\u51cf\u8f7b\u5e94\u7528\u7a0b\u5e8f\u7684\u8d1f\u8377\uff0c\u540c\u65f6\u589e\u5f3a\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u3002 \u53ef\u4ee5\u901a\u8fc7config.php\u6587\u4ef6\u7684\u914d\u7f6e\u6765\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002\u5e94\u7528\u7a0b\u5e8f\u7684\u5404\u79cd\u914d\u7f6e\u9009\u9879\u90fd\u5305\u542b\u5728config.php\u4e2d\uff0c\u8fd9\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u5728config.php\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u662f\u53ef\u884c\u7684 &#8216;log&#8217; =&gt; [ &#8216;type&#8217;&nbsp;=&amp;gt;&nbsp;&#8216;test&#8217; \u767b\u5f55\u540e\u590d\u5236 ] \u6211\u4eec\u5df2\u7ecf\u628a\u952e\u540d\u4e3a&#8221;log&#8221;\u7684\u952e\u8bbe\u7f6e\u4e3a&#8221;value&#8221;\u3002\u8fd9\u610f\u5473\u7740\u5e94\u7528\u7a0b\u5e8f\u5c06\u4e0d\u4f1a\u8bb0\u5f55\u4efb\u4f55\u65e5\u5fd7\uff0c\u800c\u662f\u53ea\u8bb0\u5f55\u4e00\u4e2a\u6d4b\u8bd5\u503c\u3002\u91c7\u7528\u8fd9\u79cd\u505a\u6cd5\u53ef\u4ee5\u907f\u514d\u5728\u5199\u65e5\u5fd7\u65f6\u8017\u8d39\u65f6\u95f4\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u3002\u5f53\u7136\uff0c\u5982\u679c\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06&#8217;test&#8217;\u952e\u7684\u503c\u8bbe\u7f6e\u4e3a&#8217;file&#8217;\uff0c\u6765\u91cd\u65b0\u6253\u5f00\u65e5\u5fd7\u8bb0\u5f55\uff0c\u65b9\u4fbf\u6392\u67e5\u95ee\u9898\u3002 \u5728\u5173\u95ed\u65e5\u5fd7\u8bb0\u5f55\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528ThinkPHP\u63d0\u4f9b\u7684getError()\u65b9\u6cd5\u6765\u83b7\u53d6\u5e94\u7528\u7a0b\u5e8f\u629b\u51fa\u7684\u5f02\u5e38\u548c\u9519\u8bef\u3002\u901a\u8fc7\u4f7f\u7528getError()\u65b9\u6cd5\uff0c\u6211\u4eec\u80fd\u591f\u5feb\u901f\u5730\u8bc6\u522b\u95ee\u9898\u5e76\u8fc5\u901f\u89e3\u51b3\u5b83\u4eec\u3002 \u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5173\u95edThinkPHP\u7684\u65e5\u5fd7\u8bb0\u5f55\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-22914","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22914","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=22914"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22914\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}