{"id":22912,"date":"2024-11-21T10:21:07","date_gmt":"2024-11-21T02:21:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22912\/"},"modified":"2024-11-21T10:21:07","modified_gmt":"2024-11-21T02:21:07","slug":"thinkphp%e4%b8%ad%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22912\/","title":{"rendered":"ThinkPHP\u4e2d\u5982\u4f55\u8bbe\u7f6e\u6784\u9020\u51fd\u6570"},"content":{"rendered":"<\/p>\n<p><strong>\u4e00\u3001\u4ec0\u4e48\u662f\u6784\u9020\u51fd\u6570<\/strong><\/p>\n<p>\u6784\u9020\u51fd\u6570\u662f\u4e00\u4e2a\u5728\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5bf9\u8c61\u65f6\u81ea\u52a8\u8c03\u7528\u7684\u7279\u6b8a\u51fd\u6570\u3002\u5b83\u7684\u4f5c\u7528\u662f\u5bf9\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u8bbe\u7f6e\u5c5e\u6027\u7684\u521d\u59cb\u503c\u7b49\u3002\u5728PHP\u4e2d\uff0c\u6784\u9020\u51fd\u6570\u7684\u540d\u79f0\u5fc5\u987b\u4e3a__construct()\u3002<\/p>\n<p><strong>\u4e8c\u3001\u5728ThinkPHP\u4e2d\u8bbe\u7f6e\u6784\u9020\u51fd\u6570\u7684\u6b65\u9aa4<\/strong><\/p>\n<ol>\n<li>\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7c7b\u6587\u4ef6\uff0c\u6bd4\u5982\u8bf4\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aPHP\u6587\u4ef6\uff0c\u547d\u540d\u4e3atest.php\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<\/li>\n<\/ol>\n<pre>&lt;?php namespace HomeModel;\nuse ThinkModel;\nclass test extends Model{\n    private $name;\n    public function __construct($name){\n        $this-&gt;name&nbsp;=&nbsp;$name;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;get_name(){\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this-&amp;gt;name;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\n<p>\u5728test\u7c7b\u91cc\u9762\uff0c\u4e00\u4e2a\u79c1\u6709\u5c5e\u6027 $name \u88ab\u5b9a\u4e49\uff0c\u540c\u65f6\u8fd8\u6709\u4e00\u4e2a\u516c\u5171\u65b9\u6cd5 get_name()\u3002\u6211\u4eec\u4f7f\u7528$name\u53c2\u6570\u5728\u6784\u9020\u51fd\u6570__construct()\u4e2d\u4e3a$name\u5c5e\u6027\u8d4b\u521d\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u4f7f\u7528test\u7c7b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u5b9e\u4f8b\u5316\u5bf9\u8c61\uff1a<\/p>\n<\/li>\n<\/ol>\n<pre>$t&nbsp;=&nbsp;new&nbsp;test(\"thinkphp\");\necho&nbsp;$t-&amp;gt;get_name();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\n<p>\u5728\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u540c\u65f6\uff0c\u6211\u4eec\u4f20\u9012\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32&#8221;&#8221;\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd9\u4e2a\u53c2\u6570\u5c06\u88ab\u4f20\u9012\u7ed9\u7c7b\u7684\u6784\u9020\u51fd\u6570__construct()\uff0c\u5e76\u88ab\u7528\u6765\u8bbe\u7f6e\u5c5e\u6027$name\u7684\u521d\u503c\u3002\u6700\u7ec8\uff0c\u6211\u4eec\u7528get_name()\u51fd\u6570\u63d0\u53d6$name\u5c5e\u6027\u7684\u503c\u5e76\u8fdb\u884c\u8f93\u51fa\u3002<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u4e09\u3001\u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u597d\u5904<\/strong><\/p>\n<p>\u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u597d\u5904\u5728\u4e8e\uff0c\u53ef\u4ee5\u5728\u7c7b\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u5c31\u5b8c\u6210\u4e00\u4e9b\u5fc5\u8981\u7684\u521d\u59cb\u5316\u64cd\u4f5c\uff0c\u907f\u514d\u4e86\u5728\u4f7f\u7528\u7c7b\u7684\u65f6\u5019\u8fd8\u8981\u5199\u4e00\u4e9b\u989d\u5916\u7684\u521d\u59cb\u5316\u4ee3\u7801\u3002\u8fd9\u6837\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP\u4e2d\u5982\u4f55\u8bbe\u7f6e\u6784\u9020\u51fd\u6570\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>\u4e00\u3001\u4ec0\u4e48\u662f\u6784\u9020\u51fd\u6570 \u6784\u9020\u51fd\u6570\u662f\u4e00\u4e2a\u5728\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5bf9\u8c61\u65f6\u81ea\u52a8\u8c03\u7528\u7684\u7279\u6b8a\u51fd\u6570\u3002\u5b83\u7684\u4f5c\u7528\u662f\u5bf9\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u8bbe\u7f6e\u5c5e\u6027\u7684\u521d\u59cb\u503c\u7b49\u3002\u5728PHP\u4e2d\uff0c\u6784\u9020\u51fd\u6570\u7684\u540d\u79f0\u5fc5\u987b\u4e3a__construct()\u3002 \u4e8c\u3001\u5728ThinkPHP\u4e2d\u8bbe\u7f6e\u6784\u9020\u51fd\u6570\u7684\u6b65\u9aa4 \u9996\u5148\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u7c7b\u6587\u4ef6\uff0c\u6bd4\u5982\u8bf4\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aPHP\u6587\u4ef6\uff0c\u547d\u540d\u4e3atest.php\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b &lt;?php namespace HomeModel; use ThinkModel; class test extends Model{ private $name; public function __construct($name){ $this-&gt;name&nbsp;=&nbsp;$name; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;get_name(){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$this-&amp;gt;name; &nbsp;&nbsp;&nbsp;&nbsp;} } \u767b\u5f55\u540e\u590d\u5236 \u5728test\u7c7b\u91cc\u9762\uff0c\u4e00\u4e2a\u79c1\u6709\u5c5e\u6027 $name \u88ab\u5b9a\u4e49\uff0c\u540c\u65f6\u8fd8\u6709\u4e00\u4e2a\u516c\u5171\u65b9\u6cd5 get_name()\u3002\u6211\u4eec\u4f7f\u7528$name\u53c2\u6570\u5728\u6784\u9020\u51fd\u6570__construct()\u4e2d\u4e3a$name\u5c5e\u6027\u8d4b\u521d\u503c\u3002 \u5728\u4f7f\u7528test\u7c7b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u5b9e\u4f8b\u5316\u5bf9\u8c61\uff1a $t&nbsp;=&nbsp;new&nbsp;test(&#8220;thinkphp&#8221;); echo&nbsp;$t-&amp;gt;get_name(); \u767b\u5f55\u540e\u590d\u5236 \u5728\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u540c\u65f6\uff0c\u6211\u4eec\u4f20\u9012\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32&#8221;&#8221;\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd9\u4e2a\u53c2\u6570\u5c06\u88ab\u4f20\u9012\u7ed9\u7c7b\u7684\u6784\u9020\u51fd\u6570__construct()\uff0c\u5e76\u88ab\u7528\u6765\u8bbe\u7f6e\u5c5e\u6027$name\u7684\u521d\u503c\u3002\u6700\u7ec8\uff0c\u6211\u4eec\u7528get_name()\u51fd\u6570\u63d0\u53d6$name\u5c5e\u6027\u7684\u503c\u5e76\u8fdb\u884c\u8f93\u51fa\u3002 \u4e09\u3001\u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u597d\u5904 \u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u597d\u5904\u5728\u4e8e\uff0c\u53ef\u4ee5\u5728\u7c7b\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u5c31\u5b8c\u6210\u4e00\u4e9b\u5fc5\u8981\u7684\u521d\u59cb\u5316\u64cd\u4f5c\uff0c\u907f\u514d\u4e86\u5728\u4f7f\u7528\u7c7b\u7684\u65f6\u5019\u8fd8\u8981\u5199\u4e00\u4e9b\u989d\u5916\u7684\u521d\u59cb\u5316\u4ee3\u7801\u3002\u8fd9\u6837\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u66f4\u52a0\u65b9\u4fbf\u3002 \u4ee5\u4e0a\u5c31\u662fThinkPHP\u4e2d\u5982\u4f55\u8bbe\u7f6e\u6784\u9020\u51fd\u6570\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-22912","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22912","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=22912"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22912\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}