{"id":25303,"date":"2024-11-21T09:54:13","date_gmt":"2024-11-21T01:54:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25303\/"},"modified":"2024-11-21T09:54:13","modified_gmt":"2024-11-21T01:54:13","slug":"thinkphp%e9%a6%96%e9%a1%b5%e6%96%87%e4%bb%b6%e5%9c%a8%e5%93%aa%e9%87%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25303\/","title":{"rendered":"thinkphp\u9996\u9875\u6587\u4ef6\u5728\u54ea\u91cc"},"content":{"rendered":"<blockquote><p>\n  thinkphp\u6846\u67b6\u4e2d\u7684\u9996\u9875\u6587\u4ef6\u7528\u4e8e\u5b9a\u4e49\u7f51\u7ad9\u9996\u9875\uff0c\u4f4d\u4e8e app\/home\/controller\/indexcontroller.php\uff0c\u5305\u542b\u4e00\u4e2a\u540d\u4e3a index \u7684\u52a8\u4f5c\u65b9\u6cd5\uff0c\u8d1f\u8d23\u5904\u7406\u9996\u9875\u8bf7\u6c42\u3002\u8be5\u65b9\u6cd5\u5305\u542b\u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5e76\u8fd4\u56de\u89c6\u56fe\u6587\u4ef6 app\/home\/view\/index\/index.html\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040917542230919.jpg\" class=\"aligncenter\" title=\"thinkphp\u9996\u9875\u6587\u4ef6\u5728\u54ea\u91cc\u63d2\u56fe\" alt=\"thinkphp\u9996\u9875\u6587\u4ef6\u5728\u54ea\u91cc\u63d2\u56fe\" \/><\/p>\n<p><strong> \u9996\u9875\u6587\u4ef6\u4f4d\u7f6e<\/strong><\/p>\n<p>ThinkPHP\u6846\u67b6\u4e2d\u7684\u9996\u9875\u6587\u4ef6\u662f\u7528\u6765\u5b9a\u4e49\u7f51\u7ad9\u9996\u9875\u7684\u63a7\u5236\u5668\u52a8\u4f5c\u3002\u5b83\u901a\u5e38\u4f4d\u4e8e\u4ee5\u4e0b\u4f4d\u7f6e\uff1a<\/p>\n<pre>app\/home\/controller\/IndexController.php<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u6587\u4ef6\u5305\u542b\u4e86\u4e00\u4e2a\u540d\u4e3aindex\u7684\u52a8\u4f5c\u65b9\u6cd5\uff0c\u8d1f\u8d23\u5904\u7406\u7f51\u7ad9\u9996\u9875\u7684\u8bf7\u6c42\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u9996\u9875\u6587\u4ef6\u7684\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>namespace apphomecontroller;\n\nuse thinkController;\n\nclass IndexController extends Controller\n{\n    public function index()\n    {\n        \/\/ \u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91\n        ...\n\n        \/\/ \u8fd4\u56de\u9996\u9875\u89c6\u56fe\n        return view();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>1. \u547d\u540d\u7a7a\u95f4\uff1a\u8be5\u6587\u4ef6\u4f4d\u4e8e `apphomecontroller` \u547d\u540d\u7a7a\u95f4\u4e2d\uff0c\u8868\u793a\u5b83\u5c5e\u4e8e\u5e94\u7528\u7684 `home` \u6a21\u5757\u3002\n\n2. \u7c7b\u5b9a\u4e49\uff1a`IndexController` \u7c7b\u7ee7\u627f\u81ea `thinkController`\uff0c\u8fd9\u662f ThinkPHP \u6846\u67b6\u63d0\u4f9b\u7684\u57fa\u7c7b\u63a7\u5236\u5668\u3002\n\n3. \u52a8\u4f5c\u65b9\u6cd5\uff1a`index` \u52a8\u4f5c\u65b9\u6cd5\u662f\u9996\u9875\u6587\u4ef6\u7684\u5165\u53e3\u51fd\u6570\uff0c\u8d1f\u8d23\u5904\u7406\u7f51\u7ad9\u9996\u9875\u7684\u8bf7\u6c42\u3002\n\n4. \u4e1a\u52a1\u903b\u8f91\uff1a\u8be5\u65b9\u6cd5\u5305\u542b\u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u4f8b\u5982\u83b7\u53d6\u6570\u636e\u3001\u6e32\u67d3\u89c6\u56fe\u7b49\u3002\n\n5. \u8fd4\u56de\u89c6\u56fe\uff1a`return view();` \u8bed\u53e5\u8fd4\u56de\u9996\u9875\u7684\u89c6\u56fe\u6587\u4ef6\u3002\u89c6\u56fe\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e `app\/home\/view\/index\/index.html`\u3002<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9996\u9875\u6587\u4ef6\u5728\u54ea\u91cc\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>thinkphp\u6846\u67b6\u4e2d\u7684\u9996\u9875\u6587\u4ef6\u7528\u4e8e\u5b9a\u4e49\u7f51\u7ad9\u9996\u9875\uff0c\u4f4d\u4e8e app\/home\/controller\/indexcontroller.php\uff0c\u5305\u542b\u4e00\u4e2a\u540d\u4e3a index \u7684\u52a8\u4f5c\u65b9\u6cd5\uff0c\u8d1f\u8d23\u5904\u7406\u9996\u9875\u8bf7\u6c42\u3002\u8be5\u65b9\u6cd5\u5305\u542b\u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5e76\u8fd4\u56de\u89c6\u56fe\u6587\u4ef6 app\/home\/view\/index\/index.html\u3002 \u9996\u9875\u6587\u4ef6\u4f4d\u7f6e ThinkPHP\u6846\u67b6\u4e2d\u7684\u9996\u9875\u6587\u4ef6\u662f\u7528\u6765\u5b9a\u4e49\u7f51\u7ad9\u9996\u9875\u7684\u63a7\u5236\u5668\u52a8\u4f5c\u3002\u5b83\u901a\u5e38\u4f4d\u4e8e\u4ee5\u4e0b\u4f4d\u7f6e\uff1a app\/home\/controller\/IndexController.php \u767b\u5f55\u540e\u590d\u5236 \u8be5\u6587\u4ef6\u5305\u542b\u4e86\u4e00\u4e2a\u540d\u4e3aindex\u7684\u52a8\u4f5c\u65b9\u6cd5\uff0c\u8d1f\u8d23\u5904\u7406\u7f51\u7ad9\u9996\u9875\u7684\u8bf7\u6c42\u3002 \u8be6\u7ec6\u8bf4\u660e \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u9996\u9875\u6587\u4ef6\u7684\u7ed3\u6784\u5982\u4e0b\uff1a namespace apphomecontroller; use thinkController; class IndexController extends Controller { public function index() { \/\/ \u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91 &#8230; \/\/ \u8fd4\u56de\u9996\u9875\u89c6\u56fe return view(); } } \u767b\u5f55\u540e\u590d\u5236 1. \u547d\u540d\u7a7a\u95f4\uff1a\u8be5\u6587\u4ef6\u4f4d\u4e8e `apphomecontroller` \u547d\u540d\u7a7a\u95f4\u4e2d\uff0c\u8868\u793a\u5b83\u5c5e\u4e8e\u5e94\u7528\u7684 `home` \u6a21\u5757\u3002 2. \u7c7b\u5b9a\u4e49\uff1a`IndexController` \u7c7b\u7ee7\u627f\u81ea `thinkController`\uff0c\u8fd9\u662f ThinkPHP \u6846\u67b6\u63d0\u4f9b\u7684\u57fa\u7c7b\u63a7\u5236\u5668\u3002 3. \u52a8\u4f5c\u65b9\u6cd5\uff1a`index` \u52a8\u4f5c\u65b9\u6cd5\u662f\u9996\u9875\u6587\u4ef6\u7684\u5165\u53e3\u51fd\u6570\uff0c\u8d1f\u8d23\u5904\u7406\u7f51\u7ad9\u9996\u9875\u7684\u8bf7\u6c42\u3002 4. \u4e1a\u52a1\u903b\u8f91\uff1a\u8be5\u65b9\u6cd5\u5305\u542b\u9996\u9875\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u4f8b\u5982\u83b7\u53d6\u6570\u636e\u3001\u6e32\u67d3\u89c6\u56fe\u7b49\u3002 5. \u8fd4\u56de\u89c6\u56fe\uff1a`return [&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-25303","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25303","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=25303"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25303\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}