{"id":48639,"date":"2024-12-02T08:16:32","date_gmt":"2024-12-02T00:16:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48639\/"},"modified":"2024-12-02T08:16:32","modified_gmt":"2024-12-02T00:16:32","slug":"%e8%ae%a4%e8%af%86-lithe%ef%bc%9a%e8%bd%bb%e9%87%8f%e7%ba%a7%e4%b8%94%e7%81%b5%e6%b4%bb%e7%9a%84-php-%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48639\/","title":{"rendered":"\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/1730177329672069313ed7f.jpg\" class=\"aligncenter\" title=\"\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6\u63d2\u56fe\" alt=\"\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6\u63d2\u56fe\" \/><\/p>\n<p>lithe \u662f\u4e00\u4e2a\u521b\u65b0\u7684 php \u6846\u67b6\uff0c\u65e8\u5728\u7075\u6d3b\u9ad8\u6548\u3002\u5b83\u5728\u6784\u5efa\u65f6\u8003\u8651\u5230\u7b80\u5355\u6027\uff0c\u501f\u9274\u4e86 express.js \u7684\u7075\u611f\uff0c\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e86\u4e00\u79cd\u521b\u5efa web \u5e94\u7528\u7a0b\u5e8f\u548c api \u7684\u76f4\u89c2\u65b9\u6cd5\u3002 lithe \u975e\u5e38\u9002\u5408\u90a3\u4e9b\u60f3\u8981\u4e00\u4e2a\u6700\u5c0f\u6846\u67b6\u800c\u53c8\u4e0d\u5f71\u54cd\u529f\u80fd\u7684\u4eba\u3002<\/p>\n<h3> \u8f7b\u76c8\u80cc\u540e\u7684\u54f2\u5b66 <\/h3>\n<p>lithe \u7684\u6784\u5efa\u8003\u8651\u5230\u4e86\u7b80\u5355\u6027\u548c\u6548\u7387\u3002\u6b63\u5982 <strong>express.js<\/strong> \u5f7b\u5e95\u6539\u53d8\u4e86 javascript \u540e\u7aef\u5f00\u53d1\u4e00\u6837\uff0clithe \u4e5f\u4e3a php \u5e26\u6765\u4e86\u7c7b\u4f3c\u7684\u65b9\u6cd5\u3002\u5176\u7406\u5ff5\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u7b80\u5355\u76f4\u89c2\u7684\u8def\u7531<\/strong>\uff1alithe \u7684\u8def\u7531\u53d7\u5230 express.js \u7684\u542f\u53d1\uff0c\u4f7f\u5176\u6613\u4e8e\u9605\u8bfb\u548c\u914d\u7f6e\u3002<\/li>\n<li> <strong>\u5f3a\u5927\u7684\u4e2d\u95f4\u4ef6<\/strong>\uff1a\u4e2d\u95f4\u4ef6\u652f\u6301\u5141\u8bb8\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u65e5\u5fd7\u8bb0\u5f55\u7b49\u6a21\u5757\u5316\u529f\u80fd\u3002<\/li>\n<li> <strong>\u4e0e\u5916\u90e8\u7ec4\u4ef6\u65e0\u7f1d\u96c6\u6210<\/strong>\uff1alithe \u9002\u5e94\u60a8\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u652f\u6301\u5404\u79cd orm\u3001\u6a21\u677f\u548c\u5e93\u3002<\/li>\n<\/ul>\n<h3> \u8def\u7531 <\/h3>\n<p>lithe \u7684\u6838\u5fc3\u662f\u5b83\u7684\u8def\u7531\u7cfb\u7edf\uff0c\u8bbe\u8ba1\u7b80\u5355\uff0c\u7075\u611f\u6765\u81ea express.js\u3002\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre>get('\/hello\/:name', function ($req, $res) {\n    $res-&gt;send('hello, ' . $req-&gt;param('name'));\n});\n<\/pre>\n<h3> \u4e2d\u95f4\u4ef6 <\/h3>\n<p>lithe \u652f\u6301\u4e2d\u95f4\u4ef6\uff0c\u53ef\u4ee5\u5168\u5c40\u5e94\u7528\u6216\u5e94\u7528\u4e8e\u7279\u5b9a\u8def\u7531\uff0c\u8f7b\u677e\u63a7\u5236 http \u8bf7\u6c42\u6d41\u3002<\/p>\n<pre>\/\/ middleware to check if the token is valid\n$ensuretokenisvalid = function ($req, $res, $next) {\n    $token = $req-&gt;param('token');\n\n    if ($token !== 'my-secret-token') {\n        return $res-&gt;send('invalid token.');\n    }\n\n    $next();\n};\n\n\/\/ protected route using the middleware\nget('\/protected\/:token', $ensuretokenisvalid, function ($req, $res) {\n    $res-&gt;send('protected content accessed successfully!');\n});\n<\/pre>\n<p>\u8fd9\u79cd\u7075\u6d3b\u7684\u8bbe\u8ba1\u786e\u4fdd\u60a8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8def\u7531\u548c\u4e2d\u95f4\u4ef6\u7ed3\u6784\u4ee5\u6ee1\u8db3\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\u3002<\/p>\n<h3> \u8868\u73b0 <\/h3>\n<p>\u867d\u7136 lithe \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u4f46\u5b83\u7684\u8bbe\u8ba1\u662f\u8f7b\u91cf\u7ea7\u7684\u3002\u5176\u6a21\u5757\u5316\u67b6\u6784\u5141\u8bb8\u60a8\u4ec5\u5305\u542b\u6240\u9700\u7684\u7ec4\u4ef6\uff0c\u4ece\u800c\u9632\u6b62\u8d44\u6e90\u8fc7\u8f7d\u3002<\/p>\n<h3> \u8f7b\u5de7\u800c\u5f3a\u5927 <\/h3>\n<p>lithe \u6846\u67b6\u65e8\u5728\u4fdd\u6301\u8f7b\u91cf\u7ea7\u800c\u4e0d\u727a\u7272\u6027\u80fd\u3002\u5176\u6a21\u5757\u5316\u67b6\u6784\u5141\u8bb8\u60a8\u4ec5\u5305\u542b\u6240\u9700\u7684\u7ec4\u4ef6\u3002\u65e0\u8bba\u662f\u6784\u5efa\u5c0f\u578b\u5e94\u7528\u7a0b\u5e8f\u8fd8\u662f\u5927\u578b\u7cfb\u7edf\uff0clithe \u90fd\u80fd\u63d0\u4f9b\u7075\u6d3b\u6027\u3002\u60a8\u53ef\u4ee5\u96c6\u6210\u60a8\u9009\u62e9\u7684\u4efb\u4f55\u6570\u636e\u5e93\uff0c\u5305\u62ec eloquent\u3001doctrine orm \u6216\u539f\u59cb sql\u3002<\/p>\n<h3> \u5b89\u88c5\u548c\u8bbe\u7f6e <\/h3>\n<p>lithe \u5165\u95e8\u975e\u5e38\u7b80\u5355\u3002\u4f7f\u7528 composer \u901a\u8fc7\u5355\u4e2a\u547d\u4ee4\u5b89\u88c5\u5b83\uff1a<\/p>\n<pre>composer create-project lithephp\/lithephp my-app\n<\/pre>\n<p>\u5b89\u88c5\u540e\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u914d\u7f6e\u8def\u7531\u548c\u4e2d\u95f4\u4ef6\u4ee5\u5f00\u59cb\u6784\u5efa\u5f3a\u5927\u7684 web \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3> \u8c01\u5e94\u8be5\u4f7f\u7528 lithe\uff1f <\/h3>\n<p>lithe \u975e\u5e38\u9002\u5408\u4ee5\u4e0b\u5f00\u53d1\u8005\uff1a<\/p>\n<ul>\n<li>\u60f3\u8981\u4e00\u4e2a\u5f3a\u8c03\u7b80\u5355\u6027\u7684\u6781\u7b80 php \u6846\u67b6\u3002<\/li>\n<li>\u6b63\u5728\u6784\u5efa restful api\uff0c\u53d7\u76ca\u4e8e\u7075\u6d3b\u7684\u8def\u7531\u3002<\/li>\n<li>\u9700\u8981\u5feb\u901f\u9ad8\u6548\u5730\u521b\u5efa\u4e2d\u5c0f\u578b\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li>\u66f4\u559c\u6b22\u96c6\u6210\u6a21\u5757\u5316\u7ec4\u4ef6\uff0c\u5982\u4e2d\u95f4\u4ef6\u3001\u6a21\u677f\u5f15\u64ce\u548c orm\u3002<\/li>\n<li>\u91cd\u89c6\u53ef\u8f7b\u677e\u5b9a\u5236\u548c\u53ef\u6269\u5c55\u7684\u8f7b\u91cf\u7ea7\u67b6\u6784\u3002<\/li>\n<li>\u5bfb\u6c42\u901a\u8fc7\u79ef\u6781\u7684\u652f\u6301\u548c\u6587\u6863\u6765\u5229\u7528\u793e\u533a\u9a71\u52a8\u7684\u5f00\u53d1\u3002 <\/li>\n<\/ul>\n<p>\u8fd9\u4f7f\u5f97 lithe \u6210\u4e3a\u5404\u79cd web \u5f00\u53d1\u9879\u76ee\u7684\u591a\u529f\u80fd\u9009\u62e9\uff01<\/p>\n<h3> \u5165\u95e8 <\/h3>\n<p>\u8981\u5f00\u59cb\u4f7f\u7528 lithe\uff0c\u8bf7\u6d4f\u89c8\u5b98\u65b9\u7f51\u7ad9\u4e0a\u7684\u7efc\u5408\u6587\u6863\u3002\u5b83\u63d0\u4f9b\u793a\u4f8b\u3001\u914d\u7f6e\u6307\u5357\u548c api \u53c2\u8003\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6 \u6536\u85cf \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300a\u8ba4\u8bc6 Lithe\uff1a\u8f7b\u91cf\u7ea7\u4e14\u7075\u6d3b\u7684 PHP \u6846\u67b6\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 lithe \u662f\u4e00\u4e2a\u521b\u65b0\u7684 php \u6846\u67b6\uff0c\u65e8\u5728\u7075\u6d3b\u9ad8\u6548\u3002\u5b83\u5728\u6784\u5efa\u65f6\u8003\u8651\u5230\u7b80\u5355\u6027\uff0c\u501f\u9274\u4e86 express.js \u7684\u7075\u611f\uff0c\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u4e86\u4e00\u79cd\u521b\u5efa web \u5e94\u7528\u7a0b\u5e8f\u548c api \u7684\u76f4\u89c2\u65b9\u6cd5\u3002 lithe \u975e\u5e38\u9002\u5408\u90a3\u4e9b\u60f3\u8981\u4e00\u4e2a\u6700\u5c0f\u6846\u67b6\u800c\u53c8\u4e0d\u5f71\u54cd\u529f\u80fd\u7684\u4eba\u3002 \u8f7b\u76c8\u80cc\u540e\u7684\u54f2\u5b66 lithe \u7684\u6784\u5efa\u8003\u8651\u5230\u4e86\u7b80\u5355\u6027\u548c\u6548\u7387\u3002\u6b63\u5982 express.js \u5f7b\u5e95\u6539\u53d8\u4e86 javascript \u540e\u7aef\u5f00\u53d1\u4e00\u6837\uff0clithe \u4e5f\u4e3a php \u5e26\u6765\u4e86\u7c7b\u4f3c\u7684\u65b9\u6cd5\u3002\u5176\u7406\u5ff5\u5305\u62ec\uff1a \u7b80\u5355\u76f4\u89c2\u7684\u8def\u7531\uff1alithe \u7684\u8def\u7531\u53d7\u5230 express.js \u7684\u542f\u53d1\uff0c\u4f7f\u5176\u6613\u4e8e\u9605\u8bfb\u548c\u914d\u7f6e\u3002 \u5f3a\u5927\u7684\u4e2d\u95f4\u4ef6\uff1a\u4e2d\u95f4\u4ef6\u652f\u6301\u5141\u8bb8\u5b9e\u73b0\u8eab\u4efd\u9a8c\u8bc1\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u65e5\u5fd7\u8bb0\u5f55\u7b49\u6a21\u5757\u5316\u529f\u80fd\u3002 \u4e0e\u5916\u90e8\u7ec4\u4ef6\u65e0\u7f1d\u96c6\u6210\uff1alithe \u9002\u5e94\u60a8\u7684\u5de5\u4f5c\u6d41\u7a0b\uff0c\u652f\u6301\u5404\u79cd orm\u3001\u6a21\u677f\u548c\u5e93\u3002 \u8def\u7531 lithe \u7684\u6838\u5fc3\u662f\u5b83\u7684\u8def\u7531\u7cfb\u7edf\uff0c\u8bbe\u8ba1\u7b80\u5355\uff0c\u7075\u611f\u6765\u81ea express.js\u3002\u8fd9\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a get(&#8216;\/hello\/:name&#8217;, function ($req, $res) { $res-&gt;send(&#8216;hello, &#8216; . $req-&gt;param(&#8216;name&#8217;)); }); \u4e2d\u95f4\u4ef6 lithe [&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-48639","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48639","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=48639"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48639\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}