{"id":46975,"date":"2024-12-02T10:15:17","date_gmt":"2024-12-02T02:15:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46975\/"},"modified":"2024-12-02T10:15:17","modified_gmt":"2024-12-02T02:15:17","slug":"%e5%91%bd%e5%90%8d%e5%8f%82%e6%95%b0%e5%9c%a8-php-%e7%94%9f%e6%80%81%e7%b3%bb%e7%bb%9f%e4%b8%ad%e5%85%b6%e4%bb%96%e7%bb%84%e4%bb%b6%ef%bc%88%e5%a6%82%e6%a1%86%e6%9e%b6%ef%bc%89%e4%b8%ad%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46975\/","title":{"rendered":"\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528<\/h1>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729857886671b895e413bb.jpg\" class=\"aligncenter\" title=\"\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528\u63d2\u56fe\" alt=\"\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\u7684\u5e94\u7528<\/strong><\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u547d\u540d\u53c2\u6570\u5141\u8bb8\u4f60\u6309\u540d\u79f0\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u6216\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u6309\u4f4d\u7f6e\u3002\u8fd9\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5177\u6709\u8bb8\u591a\u53c2\u6570\u7684\u51fd\u6570\u65f6\u3002<\/p>\n<p>\u9664\u4e86\u6838\u5fc3 PHP\uff0c\u547d\u540d\u53c2\u6570\u8fd8\u5728\u6846\u67b6\u548c\u5e93\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><strong>Laravel Framework<\/strong><\/p>\n<p>Laravel \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u8def\u7531\uff0c\u5141\u8bb8\u4f60\u5b9a\u4e49\u66f4\u5177\u63cf\u8ff0\u6027\u7684\u8def\u7531\uff1a<\/p>\n<pre>Route::get('\/user\/{id}', function ($id) {\n    \/\/ \u5904\u7406\u8bf7\u6c42...\n});<\/pre>\n<p><strong>Symfony Framework<\/strong><\/p>\n<p>Symfony \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u63a7\u5236\u5668\u52a8\u4f5c\uff0c\u5b83\u5141\u8bb8\u4f60\u5c06\u53c2\u6570\u76f4\u63a5\u6ce8\u5165\u65b9\u6cd5\uff1a<\/p>\n<pre>class UserController {\n    public function show(int $id) {\n        \/\/ \u5904\u7406\u8bf7\u6c42...\n    }\n}<\/pre>\n<p><strong>Doctrine ORM<\/strong><\/p>\n<p>Doctrine ORM \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u6765\u6784\u5efa\u67e5\u8be2\uff0c\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u9632\u6b62 SQL \u6ce8\u5165\uff1a<\/p>\n<pre>$qb = $em-&gt;createQueryBuilder()\n    -&gt;select('u')\n    -&gt;from('User', 'u')\n    -&gt;where('u.username = :username')\n    -&gt;setParameter('username', 'john');<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b\u573a\u666f\uff1a<\/p>\n<pre>function calculate(int $age, string $name, bool $active = false) {\n    \/\/ \u8ba1\u7b97...\n}<\/pre>\n<p>\u4f7f\u7528\u547d\u540d\u53c2\u6570\uff0c\u4f60\u53ef\u4ee5\u6309\u540d\u79f0\u4f20\u9012\u53c2\u6570\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>calculate(age: 30, name: 'John', active: true);<\/pre>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<p>\u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u6709\u51e0\u4e2a\u4f18\u70b9\uff1a<\/p>\n<ul>\n<li>\u53ef\u8bfb\u6027\u63d0\u9ad8<\/li>\n<li>\u53ef\u7ef4\u62a4\u6027\u63d0\u9ad8<\/li>\n<li>\u9632\u6b62\u53c2\u6570\u987a\u5e8f\u9519\u8bef<\/li>\n<li>\u51cf\u5c11 SQL \u6ce8\u5165\u7684\u98ce\u9669<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528 \u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u6587\u7ae0\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u300a\u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\uff08\u5982\u6846\u67b6\uff09\u4e2d\u7684\u5e94\u7528\u300b\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~ \u547d\u540d\u53c2\u6570\u5728 PHP \u751f\u6001\u7cfb\u7edf\u4e2d\u5176\u4ed6\u7ec4\u4ef6\u7684\u5e94\u7528 \u5728 PHP \u4e2d\uff0c\u547d\u540d\u53c2\u6570\u5141\u8bb8\u4f60\u6309\u540d\u79f0\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u6216\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u6309\u4f4d\u7f6e\u3002\u8fd9\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5177\u6709\u8bb8\u591a\u53c2\u6570\u7684\u51fd\u6570\u65f6\u3002 \u9664\u4e86\u6838\u5fc3 PHP\uff0c\u547d\u540d\u53c2\u6570\u8fd8\u5728\u6846\u67b6\u548c\u5e93\u4e2d\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\uff0c\u4f8b\u5982\uff1a Laravel Framework Laravel \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u8def\u7531\uff0c\u5141\u8bb8\u4f60\u5b9a\u4e49\u66f4\u5177\u63cf\u8ff0\u6027\u7684\u8def\u7531\uff1a Route::get(&#8216;\/user\/{id}&#8217;, function ($id) { \/\/ \u5904\u7406\u8bf7\u6c42&#8230; }); Symfony Framework Symfony \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u63a7\u5236\u5668\u52a8\u4f5c\uff0c\u5b83\u5141\u8bb8\u4f60\u5c06\u53c2\u6570\u76f4\u63a5\u6ce8\u5165\u65b9\u6cd5\uff1a class UserController { public function show(int $id) { \/\/ \u5904\u7406\u8bf7\u6c42&#8230; } } Doctrine ORM Doctrine ORM \u4f7f\u7528\u547d\u540d\u7684\u53c2\u6570\u6765\u6784\u5efa\u67e5\u8be2\uff0c\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u53ef\u8bfb\u6027\u548c\u9632\u6b62 SQL \u6ce8\u5165\uff1a $qb = $em-&gt;createQueryBuilder() -&gt;select(&#8216;u&#8217;) -&gt;from(&#8216;User&#8217;, &#8216;u&#8217;) -&gt;where(&#8216;u.username [&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-46975","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46975","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=46975"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46975\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}