{"id":59809,"date":"2023-10-30T10:06:56","date_gmt":"2023-10-30T02:06:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=59809"},"modified":"2023-10-30T10:06:58","modified_gmt":"2023-10-30T02:06:58","slug":"thinkphp%e6%80%8e%e4%b9%88%e5%af%bc%e5%85%a5%e7%ac%ac%e4%b8%89%e6%96%b9%e7%b1%bb%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/59809.html","title":{"rendered":"ThinkPHP\u600e\u4e48\u5bfc\u5165\u7b2c\u4e09\u65b9\u7c7b\u5e93"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u200bThinkPHP\u6846\u67b6\u4e3aPHP\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u9ad8\u6548\u7387\u3001\u7b80\u5355\u3001\u5b89\u5168\u7684\u6280\u672f\u89e3\u51b3\u65b9\u6848\uff0c\u5176\u4e2d\u5305\u62ec\u65b9\u4fbf\u7684\u7b2c\u4e09\u65b9\u7c7b\u5e93\u5bfc\u5165\u529f\u80fd\u3002\u6587\u7ae0\u5c06\u6307\u5bfc\u4f60\uff1a1.\u4e86\u89e3Composer\u548cThinkPHP\u7684\u5173\u8054\uff1b2.\u624b\u52a8\u5bfc\u5165\u7c7b\u5e93\u7684\u6b65\u9aa4\uff1b3.\u4f7f\u7528Composer\u81ea\u52a8\u5bfc\u5165\uff1b4.\u8c03\u7528\u7b2c\u4e09\u65b9\u7c7b\u5e93\uff1b5.\u907f\u514d\u5e38\u89c1\u9519\u8bef\u3002\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3Composer\u7684\u57fa\u672c\u529f\u80fd\u548c\u4f5c\u7528\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u4e86\u89e3Composer\u548cThinkPHP\u7684\u5173\u8054 <\/h2>\n\n\n\n<p>Composer\u662fPHP\u7684\u4e00\u4e2a\u4f9d\u8d56\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u81ea\u52a8\u5b89\u88c5\u548c\u7ba1\u7406\u9879\u76ee\u6240\u9700\u7684\u5e93\u548c\u7ec4\u4ef6\u3002\u800cThinkPHP\u6846\u67b6\u4e0eComposer\u7684\u6574\u5408\uff0c\u4f7f\u5f97\u5bfc\u5165\u7b2c\u4e09\u65b9\u7c7b\u5e93\u53d8\u5f97\u7b80\u5355\u800c\u9ad8\u6548\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u624b\u52a8\u5bfc\u5165\u7c7b\u5e93\u7684\u6b65\u9aa4 <\/h2>\n\n\n\n<p>\u867d\u7136Composer\u662f\u81ea\u52a8\u5316\u7684\u9996\u9009\uff0c\u4f46\u6709\u65f6\u4f60\u53ef\u80fd\u9700\u8981\u624b\u52a8\u5bfc\u5165\u7c7b\u5e93\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a a. \u4e0b\u8f7d\u4f60\u9700\u8981\u7684\u7b2c\u4e09\u65b9\u7c7b\u5e93\u3002 b. \u5c06\u4e0b\u8f7d\u7684\u7c7b\u5e93\u590d\u5236\u5230ThinkPHP\u7684\u201cextend\u201d\u76ee\u5f55\u4e2d\u3002 c. \u5728\u5e94\u7528\u4e2d\u4f7f\u7528namespace\u6765\u5f15\u7528\u8be5\u7c7b\u5e93\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u4f7f\u7528Composer\u81ea\u52a8\u5bfc\u5165 <\/h2>\n\n\n\n<p>a. \u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u5de5\u5177\u3002 <\/p>\n\n\n\n<p>b. \u4f7f\u7528<code>composer require \u4f9b\u5e94\u5546\/\u5e93\u540d\u79f0<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u9700\u7684\u7c7b\u5e93\u3002<\/p>\n\n\n\n<p> c. Composer\u4f1a\u81ea\u52a8\u5904\u7406\u6240\u6709\u7684\u4f9d\u8d56\u548c\u81ea\u52a8\u52a0\u8f7d\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u8c03\u7528\u7b2c\u4e09\u65b9\u7c7b\u5e93 <\/h2>\n\n\n\n<p>\u4e00\u65e6\u4f60\u5bfc\u5165\u4e86\u6240\u9700\u7684\u7c7b\u5e93\uff0c\u53ef\u4ee5\u5728ThinkPHP\u9879\u76ee\u4e2d\u8f7b\u677e\u8c03\u7528\u5b83\uff1a a. \u4f7f\u7528<code>use<\/code>\u5173\u952e\u5b57\u5bfc\u5165\u7c7b\u5e93\u3002 b. \u521b\u5efa\u7c7b\u5e93\u7684\u5b9e\u4f8b\u6216\u8c03\u7528\u5176\u9759\u6001\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u907f\u514d\u5e38\u89c1\u9519\u8bef <\/h2>\n\n\n\n<p>\u5728\u5bfc\u5165\u548c\u4f7f\u7528\u7b2c\u4e09\u65b9\u7c7b\u5e93\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\uff0c\u5982\uff1a a. \u5fd8\u8bb0\u5728composer.json\u4e2d\u6dfb\u52a0\u4f9d\u8d56\u3002 b. \u547d\u540d\u7a7a\u95f4\u6216\u8def\u5f84\u9519\u8bef\u3002 c. \u7c7b\u5e93\u4e0eThinkPHP\u7248\u672c\u4e0d\u517c\u5bb9\u3002 \u786e\u4fdd\u59cb\u7ec8\u68c0\u67e5\u6846\u67b6\u548c\u7c7b\u5e93\u7684\u6587\u6863\uff0c\u4ee5\u786e\u4fdd\u4f60\u6b63\u786e\u5730\u5bfc\u5165\u548c\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n\n\n\n<p>\u7ed3\u8bba\uff1a ThinkPHP\u63d0\u4f9b\u4e86\u7075\u6d3b\u548c\u9ad8\u6548\u7684\u65b9\u6cd5\u6765\u5bfc\u5165\u7b2c\u4e09\u65b9\u7c7b\u5e93\uff0c\u65e0\u8bba\u662f\u624b\u52a8\u8fd8\u662f\u4f7f\u7528Composer\u3002\u53ea\u8981\u4f60\u9075\u5faa\u6b63\u786e\u7684\u6b65\u9aa4\u5e76\u6ce8\u610f\u5e38\u89c1\u7684\u9677\u9631\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u6269\u5c55\u4f60\u7684\u5e94\u7528\u7684\u529f\u80fd\u3002\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u4f60\u4f1a\u53d1\u73b0\uff0c\u65e0\u8bba\u9879\u76ee\u7684\u5927\u5c0f\uff0c\u90fd\u53ef\u4ee5\u8f7b\u677e\u5730\u96c6\u6210\u548c\u4f7f\u7528\u7b2c\u4e09\u65b9\u7c7b\u5e93\uff0c\u4ece\u800c\u66f4\u597d\u5730\u4e3a\u4f60\u7684\u7528\u6237\u63d0\u4f9b\u5353\u8d8a\u7684\u670d\u52a1\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"484\" height=\"300\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u5728\u9e92\u9e9f\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u7ba1\u7406\u5b57\u4f53-2023-10-30T100516.110.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-59810\" \/><\/figure><\/div>\n\n\n<p><strong>\u5e38\u89c1\u95ee\u7b54<\/strong>\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>Q1: \u5728ThinkPHP\u4e2d\uff0c\u6211\u662f\u5426\u5fc5\u987b\u4f7f\u7528Composer\u6765\u5bfc\u5165\u7b2c\u4e09\u65b9\u7c7b\u5e93\uff1f<\/strong><\/li>\n\n\n\n<li><strong>A1:<\/strong> \u4e0d\u662f\u5fc5\u987b\u7684\u3002\u867d\u7136Composer\u63d0\u4f9b\u4e86\u4e00\u4e2a\u81ea\u52a8\u5316\u7684\u65b9\u6cd5\u6765\u5bfc\u5165\u548c\u7ba1\u7406\u4f9d\u8d56\uff0c\u4f46ThinkPHP\u4e5f\u5141\u8bb8\u4f60\u624b\u52a8\u5bfc\u5165\u7c7b\u5e93\u3002\u4f60\u53ef\u4ee5\u76f4\u63a5\u5c06\u7b2c\u4e09\u65b9\u7c7b\u5e93\u653e\u5165\u201cextend\u201d\u76ee\u5f55\u4e2d\uff0c\u5e76\u5728\u4ee3\u7801\u4e2d\u901a\u8fc7namespace\u6765\u5f15\u7528\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Q2: \u5982\u679c\u6211\u5bfc\u5165\u7684\u7b2c\u4e09\u65b9\u7c7b\u5e93\u548cThinkPHP\u6846\u67b6\u4e0d\u517c\u5bb9\u600e\u4e48\u529e\uff1f<\/strong><\/li>\n\n\n\n<li><strong>A2:<\/strong> \u9996\u5148\uff0c\u786e\u4fdd\u68c0\u67e5\u8be5\u7b2c\u4e09\u65b9\u7c7b\u5e93\u7684\u6587\u6863\u6216\u5b98\u65b9\u7f51\u7ad9\uff0c\u67e5\u770b\u662f\u5426\u6709\u7279\u5b9a\u4e8eThinkPHP\u7684\u7248\u672c\u6216\u5efa\u8bae\u3002\u5982\u679c\u6ca1\u6709\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5bfb\u627e\u53e6\u4e00\u4e2a\u4e0eThinkPHP\u66f4\u517c\u5bb9\u7684\u7c7b\u5e93\uff0c\u6216\u8003\u8651\u624b\u52a8\u8fdb\u884c\u4e00\u4e9b\u8c03\u6574\u4f7f\u5176\u4e0eThinkPHP\u6846\u67b6\u517c\u5bb9\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Q3: \u6211\u5982\u4f55\u77e5\u9053\u6211\u9700\u8981\u54ea\u4e2a\u7248\u672c\u7684\u7b2c\u4e09\u65b9\u7c7b\u5e93\uff1f<\/strong><\/li>\n\n\n\n<li><strong>A3:<\/strong> \u901a\u5e38\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b\u7c7b\u5e93\u7684\u5b98\u65b9\u6587\u6863\u6216\u5176\u5728GitHub\u4e0a\u7684README\u6587\u4ef6\uff0c\u8fd9\u4e9b\u901a\u5e38\u4f1a\u5217\u51fa\u7c7b\u5e93\u7684\u7248\u672c\u4fe1\u606f\u53ca\u5176\u4e0e\u5176\u4ed6\u9879\u76ee\u6216\u6846\u67b6\u7684\u517c\u5bb9\u6027\u3002\u5982\u679c\u4f7f\u7528Composer\uff0c\u5b83\u4f1a\u5e2e\u52a9\u4f60\u9009\u62e9\u548c\u7ba1\u7406\u4e0e\u4f60\u7684\u9879\u76ee\u517c\u5bb9\u7684\u7248\u672c\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>Q4: \u5982\u679c\u6211\u5df2\u7ecf\u624b\u52a8\u5bfc\u5165\u4e86\u4e00\u4e2a\u7c7b\u5e93\uff0c\u540e\u6765\u53c8\u60f3\u901a\u8fc7Composer\u7ba1\u7406\u600e\u4e48\u529e\uff1f<\/strong><\/li>\n\n\n\n<li><strong>A4:<\/strong> \u4f60\u53ef\u4ee5\u4f7f\u7528Composer\u547d\u4ee4\u6765\u6dfb\u52a0\u8be5\u7c7b\u5e93\u4f5c\u4e3a\u4f60\u9879\u76ee\u7684\u4f9d\u8d56\u3002\u53ea\u9700\u786e\u4fdd\u5728\u5bfc\u5165\u65b0\u7684\u7c7b\u5e93\u7248\u672c\u4e4b\u524d\uff0c\u4ece\u201cextend\u201d\u76ee\u5f55\u4e2d\u79fb\u9664\u624b\u52a8\u5bfc\u5165\u7684\u65e7\u7248\u672c\uff0c\u4ee5\u907f\u514d\u7248\u672c\u51b2\u7a81\u6216\u5176\u4ed6\u6f5c\u5728\u95ee\u9898\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u200bThinkPHP\u6846\u67b6\u4e3aPHP\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u9ad8\u6548\u7387\u3001\u7b80\u5355\u3001\u5b89\u5168\u7684\u6280\u672f\u89e3\u51b3\u65b9\u6848\uff0c\u5176\u4e2d\u5305\u62ec\u65b9\u4fbf\u7684\u7b2c\u4e09\u65b9\u7c7b\u5e93\u5bfc\u5165\u529f\u80fd\u3002 [&hellip;]","protected":false},"author":7,"featured_media":59810,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/59809"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=59809"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/59809\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/59810"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=59809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=59809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=59809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}