{"id":48006,"date":"2024-12-02T15:55:57","date_gmt":"2024-12-02T07:55:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48006\/"},"modified":"2024-12-02T15:55:57","modified_gmt":"2024-12-02T07:55:57","slug":"%e5%93%aa%e4%ba%9b-php-%e6%a1%86%e6%9e%b6%e6%94%af%e6%8c%81%e5%87%bd%e6%95%b0%e6%89%a9%e5%b1%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48006\/","title":{"rendered":"\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p>\u4ee5\u4e0b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1aSymfonyLaravelZend FrameworkPhalconCodeIgniter\u5728\u8fd9\u4e9b\u6846\u67b6\u4e2d\uff0c\u4f7f\u7528\u51fd\u6570\u6269\u5c55\u7b80\u5355\uff0c\u901a\u5e38\u6d89\u53ca\u521b\u5efa\u6216\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729948703671cec1fbdec7.jpg\" class=\"aligncenter\" title=\"\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f\u63d2\u56fe\" alt=\"\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u6269\u5c55\u51fd\u6570\uff1a\u652f\u6301\u6846\u67b6\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>PHP \u6269\u5c55\u51fd\u6570\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u6269\u5c55 PHP \u7684\u529f\u80fd\uff0c\u6dfb\u52a0\u81ea\u5b9a\u4e49\u529f\u80fd\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u652f\u6301\u51fd\u6570\u6269\u5c55\u7684 PHP \u6846\u67b6\u3002<\/p>\n<p><strong>\u652f\u6301\u51fd\u6570\u6269\u5c55\u7684 PHP \u6846\u67b6<\/strong><\/p>\n<p>\u4ee5\u4e0b\u6d41\u884c\u7684 PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1a<\/p>\n<ul>\n<li><strong>Symfony<\/strong><\/li>\n<li><strong>Laravel<\/strong><\/li>\n<li><strong>Zend Framework<\/strong><\/li>\n<li><strong>Phalcon<\/strong><\/li>\n<li><strong>CodeIgniter<\/strong><\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5<\/strong><\/p>\n<p>\u5728\u8fd9\u4e9b\u6846\u67b6\u4e2d\u4f7f\u7528\u51fd\u6570\u6269\u5c55\u975e\u5e38\u7b80\u5355\u3002\u901a\u5e38\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u529f\u80fd\u521b\u5efa\u6216\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728 Laravel \u4e2d\u6ce8\u518c\u51fd\u6570\u6269\u5c55\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>use Illuminate\\Support\\Facades\\Facade;\n\nclass CustomFunctionFacade extends Facade\n{\n    protected static function getFacadeAccessor()\n    {\n        return 'custom_function';\n    }\n}<\/pre>\n<pre>\/\/ \u5728 app\/Providers\/AppServiceProvider.php \u4e2d\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u670d\u52a1\nuse App\\Http\\Functions\\CustomFunction;\n\npublic function register()\n{\n    $this-&gt;app-&gt;singleton('custom_function', function () {\n        return new CustomFunction();\n    });\n}<\/pre>\n<pre>\/\/ \u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\nCustomFunctionFacade::myCustomFunction();<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b\uff1a\u5728 Laravel \u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u5e2e\u52a9\u5668<\/strong><\/p>\n<p>\u4e3a\u4e86\u8bf4\u660e\u51fd\u6570\u6269\u5c55\u7684\u4f7f\u7528\uff0c\u8ba9\u6211\u4eec\u5728 Laravel \u4e2d\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5b57\u7b26\u4e32\u5e2e\u52a9\u5668\u51fd\u6570\u3002<\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa <code>app\/Http\/Functions\/StringHelper.php<\/code> \u6587\u4ef6\uff1a<\/p>\n<pre>namespace App\\Http\\Functions;\n\nclass StringHelper\n{\n    public function titleCase($string)\n    {\n        return ucwords(strtolower($string));\n    }\n}<\/pre>\n<p>\u7136\u540e\uff0c\u5728 <code>providers.php<\/code> \u6587\u4ef6\u4e2d\u6ce8\u518c\u670d\u52a1\uff1a<\/p>\n<pre>use App\\Http\\Functions\\StringHelper;\n\nreturn [\n    ...\n    'providers' =&gt; [\n        ...\n        App\\Providers\\AppServiceProvider::class,\n    ],\n    ...\n    'aliases' =&gt; [\n        ...\n        'StringHelper' =&gt; App\\Http\\Functions\\StringHelperFacade::class,\n    ],\n    ...\n];<\/pre>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>StringHelper::titleCase()<\/code> \u51fd\u6570\u8f6c\u6362\u5b57\u7b26\u4e32\u4e3a\u6807\u9898\u5927\u5c0f\u5199\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u51fd\u6570\u6269\u5c55\u4e3a PHP \u6846\u67b6\u589e\u52a0\u4e86\u989d\u5916\u7684\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u6269\u5c55\u6846\u67b6\u7684\u529f\u80fd\u3002\u672c\u6587\u4e2d\u8ba8\u8bba\u7684\u6846\u67b6\u63d0\u4f9b\u4e86\u4f7f\u7528\u51fd\u6570\u6269\u5c55\u7684\u7b80\u5355\u65b9\u6cd5\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u521b\u5efa\u81ea\u5b9a\u4e49\u529f\u80fd\u5e76\u589e\u5f3a\u5176\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f \u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587\u300a\u54ea\u4e9b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1f\u300b\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a\u6587\u7ae0\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~ \u4ee5\u4e0b PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1aSymfonyLaravelZend FrameworkPhalconCodeIgniter\u5728\u8fd9\u4e9b\u6846\u67b6\u4e2d\uff0c\u4f7f\u7528\u51fd\u6570\u6269\u5c55\u7b80\u5355\uff0c\u901a\u5e38\u6d89\u53ca\u521b\u5efa\u6216\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u3002 PHP \u6269\u5c55\u51fd\u6570\uff1a\u652f\u6301\u6846\u67b6\u8be6\u89e3 \u5f15\u8a00 PHP \u6269\u5c55\u51fd\u6570\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u6269\u5c55 PHP \u7684\u529f\u80fd\uff0c\u6dfb\u52a0\u81ea\u5b9a\u4e49\u529f\u80fd\u3002\u672c\u6587\u5c06\u8ba8\u8bba\u652f\u6301\u51fd\u6570\u6269\u5c55\u7684 PHP \u6846\u67b6\u3002 \u652f\u6301\u51fd\u6570\u6269\u5c55\u7684 PHP \u6846\u67b6 \u4ee5\u4e0b\u6d41\u884c\u7684 PHP \u6846\u67b6\u652f\u6301\u51fd\u6570\u6269\u5c55\uff1a Symfony Laravel Zend Framework Phalcon CodeIgniter \u7528\u6cd5 \u5728\u8fd9\u4e9b\u6846\u67b6\u4e2d\u4f7f\u7528\u51fd\u6570\u6269\u5c55\u975e\u5e38\u7b80\u5355\u3002\u901a\u5e38\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6846\u67b6\u63d0\u4f9b\u7684\u529f\u80fd\u521b\u5efa\u6216\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728 Laravel \u4e2d\u6ce8\u518c\u51fd\u6570\u6269\u5c55\u7684\u793a\u4f8b\uff1a use Illuminate\\Support\\Facades\\Facade; class CustomFunctionFacade extends Facade { protected static function getFacadeAccessor() { return &#8216;custom_function&#8217;; } } \/\/ \u5728 app\/Providers\/AppServiceProvider.php \u4e2d\u6ce8\u518c\u81ea\u5b9a\u4e49\u51fd\u6570\u670d\u52a1 [&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-48006","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48006","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=48006"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48006\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}