{"id":24081,"date":"2024-11-21T13:17:27","date_gmt":"2024-11-21T05:17:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24081\/"},"modified":"2024-11-21T13:17:27","modified_gmt":"2024-11-21T05:17:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8webman%e6%a1%86%e6%9e%b6%e5%ae%9e%e7%8e%b0%e7%bd%91%e7%ab%99%e6%80%a7%e8%83%bd%e7%9b%91%e6%8e%a7%e5%92%8c%e9%94%99%e8%af%af%e6%97%a5%e5%bf%97%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24081\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\uff1f<\/p>\n<p>Webman\u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684PHP\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\u548c\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u9ad8\u6027\u80fd\u548c\u53ef\u9760\u7684\u7f51\u7ad9\u3002\u5176\u4e2d\uff0c\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u662f\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\uff0c\u5e76\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u529f\u80fd\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728Webman\u9879\u76ee\u4e2d\u5f15\u5165\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\u3002\u5728Webman\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7composer\u6765\u7ba1\u7406\u4f9d\u8d56\uff0c\u56e0\u6b64\u9996\u5148\u9700\u8981\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u7684composer.json\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>\"require\": {\n    \"webman\/webman\": \"1.1\",\n    \"phpmailer\/phpmailer\": \"^6.1\"\n},<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\uff0c\u6267\u884ccomposer install\u547d\u4ee4\u6765\u5b89\u88c5\u4f9d\u8d56\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728\u9879\u76ee\u7684\u5165\u53e3\u6587\u4ef6\uff08\u4e00\u822c\u662fpublic\/index.php\uff09\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u6765\u5f00\u542f\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\uff1a<\/p>\n<pre>use webmanhelperTrace;\nuse webmanhelperLog;\n\n\/\/ \u542f\u7528\u6027\u80fd\u76d1\u63a7\nTrace::enable();\n\n\/\/ \u542f\u7528\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\nLog::enable();\nLog::config([\n    'type' =&amp;gt; 'file',      \/\/ \u65e5\u5fd7\u7c7b\u578b\uff0c\u8fd9\u91cc\u4f7f\u7528\u6587\u4ef6\u8bb0\u5f55\n    'path' =&amp;gt; runtime_path(),   \/\/ \u65e5\u5fd7\u4fdd\u5b58\u8def\u5f84\n    'level' =&amp;gt; ['notice', 'error'],  \/\/ \u8bb0\u5f55\u7684\u9519\u8bef\u7ea7\u522b\n]);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528Trace::enable()\u6765\u542f\u7528\u6027\u80fd\u76d1\u63a7\u7684\u529f\u80fd\uff0c\u7136\u540e\u4f7f\u7528Log::enable()\u6765\u542f\u7528\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528Log::config()\u65b9\u6cd5\u6765\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5176\u4e2dtype\u53c2\u6570\u6307\u5b9a\u4e86\u8bb0\u5f55\u7c7b\u578b\u4e3a\u6587\u4ef6\u8bb0\u5f55\uff0cpath\u53c2\u6570\u6307\u5b9a\u4e86\u65e5\u5fd7\u4fdd\u5b58\u7684\u8def\u5f84\uff0clevel\u53c2\u6570\u6307\u5b9a\u4e86\u8bb0\u5f55\u7684\u9519\u8bef\u7ea7\u522b\u3002<\/p>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u914d\u7f6e\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u7f51\u7ad9\u6765\u89e6\u53d1\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u6765\u6f14\u793a\u5177\u4f53\u7684\u4f7f\u7528\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u63a7\u5236\u5668\uff0c\u4f8b\u5982\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6app\/controller\/Index.php\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;?php namespace appcontroller;\n\nuse webmanController;\nuse webmanhelperLog;\n\nclass Index extends Controller\n{\n    public function index()\n    {\n        \/\/ \u5728\u63a7\u5236\u5668\u4e2d\u8bb0\u5f55\u65e5\u5fd7\n        Log::notice('Hello, Webman!');\n\n        \/\/ \u8fd4\u56de\u4e00\u4e2a\u54cd\u5e94\n        return response('Hello, Webman!');\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4ee5\u4e0a\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528use webmanhelperLog;\u6765\u5f15\u5165\u65e5\u5fd7\u8bb0\u5f55\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u7136\u540e\u5728index()\u65b9\u6cd5\u4e2d\u4f7f\u7528Log::notice(&#8216;Hello, Webman!&#8217;);\u6765\u8bb0\u5f55\u4e00\u6761\u65e5\u5fd7\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528return response(&#8216;Hello, Webman!&#8217;);\u6765\u8fd4\u56de\u4e00\u4e2a\u54cd\u5e94\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5728\u8def\u7531\u914d\u7f6e\u6587\u4ef6\uff08\u4e00\u822c\u662fconfig\/router.php\uff09\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u6765\u8bbe\u7f6e\u8def\u7531\u89c4\u5219\uff1a<\/p>\n<pre>&lt;?php use webmanRoute;\n\n\/\/ \u5b9a\u4e49\u8bbf\u95ee\u6839\u76ee\u5f55\u65f6\u7684\u8def\u7531\u89c4\u5219\nRoute::get('\/', 'appcontrollerIndex@index');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u6839\u76ee\u5f55\u6765\u89e6\u53d1\u7f51\u7ad9\u7684\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u529f\u80fd\u3002<\/p>\n<p>\u6027\u80fd\u76d1\u63a7\u65e5\u5fd7\u548c\u9519\u8bef\u65e5\u5fd7\u5c06\u4f1a\u4fdd\u5b58\u5728\u8fd0\u884c\u76ee\u5f55\u7684logs\u5b50\u76ee\u5f55\u4e2d\uff0c\u901a\u8fc7\u67e5\u770b\u65e5\u5fd7\u6587\u4ef6\u53ef\u4ee5\u4e86\u89e3\u5230\u6bcf\u4e2a\u8bf7\u6c42\u7684\u6027\u80fd\u548c\u9519\u8bef\u7ec6\u8282\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u975e\u5e38\u7b80\u5355\u3002\u901a\u8fc7\u5f15\u5165\u76f8\u5173\u4f9d\u8d56\uff0c\u5f00\u542f\u76f8\u5173\u529f\u80fd\uff0c\u5e76\u914d\u7f6e\u76f8\u5173\u4fe1\u606f\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u76d1\u63a7\u7f51\u7ad9\u7684\u6027\u80fd\u548c\u8bb0\u5f55\u9519\u8bef\u65e5\u5fd7\u3002\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\uff0c\u5e76\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\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>\u5982\u4f55\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\uff1f Webman\u662f\u4e00\u4e2a\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684PHP\u6846\u67b6\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\u548c\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u9ad8\u6027\u80fd\u548c\u53ef\u9760\u7684\u7f51\u7ad9\u3002\u5176\u4e2d\uff0c\u7f51\u7ad9\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u662f\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u95ee\u9898\uff0c\u5e76\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u8fd9\u4e24\u4e2a\u529f\u80fd\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728Webman\u9879\u76ee\u4e2d\u5f15\u5165\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\u3002\u5728Webman\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7composer\u6765\u7ba1\u7406\u4f9d\u8d56\uff0c\u56e0\u6b64\u9996\u5148\u9700\u8981\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u7684composer.json\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a &#8220;require&#8221;: { &#8220;webman\/webman&#8221;: &#8220;1.1&#8221;, &#8220;phpmailer\/phpmailer&#8221;: &#8220;^6.1&#8221; }, \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u6267\u884ccomposer install\u547d\u4ee4\u6765\u5b89\u88c5\u4f9d\u8d56\u3002 \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5728\u9879\u76ee\u7684\u5165\u53e3\u6587\u4ef6\uff08\u4e00\u822c\u662fpublic\/index.php\uff09\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\u6765\u5f00\u542f\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\uff1a use webmanhelperTrace; use webmanhelperLog; \/\/ \u542f\u7528\u6027\u80fd\u76d1\u63a7 Trace::enable(); \/\/ \u542f\u7528\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55 Log::enable(); Log::config([ &#8216;type&#8217; =&amp;gt; &#8216;file&#8217;, \/\/ \u65e5\u5fd7\u7c7b\u578b\uff0c\u8fd9\u91cc\u4f7f\u7528\u6587\u4ef6\u8bb0\u5f55 &#8216;path&#8217; =&amp;gt; runtime_path(), \/\/ \u65e5\u5fd7\u4fdd\u5b58\u8def\u5f84 &#8216;level&#8217; =&amp;gt; [&#8216;notice&#8217;, &#8216;error&#8217;], \/\/ \u8bb0\u5f55\u7684\u9519\u8bef\u7ea7\u522b ]); \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528Trace::enable()\u6765\u542f\u7528\u6027\u80fd\u76d1\u63a7\u7684\u529f\u80fd\uff0c\u7136\u540e\u4f7f\u7528Log::enable()\u6765\u542f\u7528\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\u3002\u63a5\u7740\uff0c\u6211\u4eec\u4f7f\u7528Log::config()\u65b9\u6cd5\u6765\u914d\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5176\u4e2dtype\u53c2\u6570\u6307\u5b9a\u4e86\u8bb0\u5f55\u7c7b\u578b\u4e3a\u6587\u4ef6\u8bb0\u5f55\uff0cpath\u53c2\u6570\u6307\u5b9a\u4e86\u65e5\u5fd7\u4fdd\u5b58\u7684\u8def\u5f84\uff0clevel\u53c2\u6570\u6307\u5b9a\u4e86\u8bb0\u5f55\u7684\u9519\u8bef\u7ea7\u522b\u3002 \u5b8c\u6210\u4ee5\u4e0a\u914d\u7f6e\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee\u7f51\u7ad9\u6765\u89e6\u53d1\u6027\u80fd\u76d1\u63a7\u548c\u9519\u8bef\u65e5\u5fd7\u8bb0\u5f55\u7684\u529f\u80fd\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u6765\u6f14\u793a\u5177\u4f53\u7684\u4f7f\u7528\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u63a7\u5236\u5668\uff0c\u4f8b\u5982\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6app\/controller\/Index.php\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a &lt;?php namespace appcontroller; use webmanController; use webmanhelperLog; class Index [&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-24081","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24081","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=24081"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24081\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}