{"id":561,"date":"2017-03-18T14:57:57","date_gmt":"2017-03-18T06:57:57","guid":{"rendered":"http:\/\/loveuhouse.cn\/wordpress\/?p=561"},"modified":"2017-04-07T10:24:31","modified_gmt":"2017-04-07T02:24:31","slug":"thinkphp-5-%e8%b8%a9%e5%9d%91%e8%ae%b0%e5%bd%95%e3%80%90%e6%8c%81%e7%bb%ad%e6%9b%b4%e6%96%b0%e3%80%91","status":"publish","type":"post","link":"https:\/\/loveuhouse.cn\/wordpress\/?p=561","title":{"rendered":"thinkphp 5 \u8e29\u5751\u8bb0\u5f55\u3010\u6301\u7eed\u66f4\u65b0217.03.25\u3011"},"content":{"rendered":"<blockquote><p>\n  \u8fd9\u662f\u4e00\u4e2aTP3.2\u7684\u4e2d\u5ea6\u5f00\u53d1\u8005\u7684\u5b66\u4e60\u8bb0\u5f55\n<\/p><\/blockquote>\n<h2><strong>TP5 \u5b89\u88c5\u8fc7\u7a0b<\/strong><\/h2>\n<p>\u6682\u65f6\u53ea\u63d0\u4f9b \u5b98\u7f51\u4e0b\u8f7d \u5b8c\u6574\u7248\u7684\u5b89\u88c5\u65b9\u6cd5\uff0c\u5e76\u5c3d\u91cf\u8c03\u6574\u52303.2\u7684\u5f00\u53d1\u4e60\u60ef\uff0ctp5\u9700\u8981\u5728php5.4\u4ee5\u4e0a\u4e14\u975ephp6\u7684\u73af\u5883\u8fd0\u884c\u3002<\/p>\n<ul>\n<li>\u4e0b\u8f7d<code>thinkphp_5.0.5_full.zip<\/code>\u6587\u4ef6\uff0c\u5e76\u89e3\u538b\u5230WWW\u76ee\u5f55\uff0c\u91cd\u547d\u540d\u4e3atp5 \u3002<br \/>\n\u6b64\u65f6\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<br \/>\ntp5<br \/>\n\u251c\u2500application           \u5e94\u7528\u76ee\u5f55<br \/>\n\u251c\u2500public                WEB\u76ee\u5f55\uff08\u5bf9\u5916\u8bbf\u95ee\u76ee\u5f55\uff09<br \/>\n\u251c\u2500thinkphp              \u6846\u67b6\u7cfb\u7edf\u76ee\u5f55<br \/>\n\u251c\u2500extend                \u6269\u5c55\u7c7b\u5e93\u76ee\u5f55<br \/>\n\u251c\u2500runtime               \u5e94\u7528\u7684\u8fd0\u884c\u65f6\u76ee\u5f55\uff08\u53ef\u5199\uff0c\u53ef\u5b9a\u5236\uff09<br \/>\n\u251c\u2500vendor                \u7b2c\u4e09\u65b9\u7c7b\u5e93\u76ee\u5f55\uff08Composer\u4f9d\u8d56\u5e93\uff09<br \/>\n\u251c\u2500build.php             \u81ea\u52a8\u751f\u6210\u5b9a\u4e49\u6587\u4ef6\uff08\u53c2\u8003\uff09<br \/>\n\u251c\u2500composer.json         composer \u5b9a\u4e49\u6587\u4ef6<br \/>\n\u251c\u2500LICENSE.txt           \u6388\u6743\u8bf4\u660e\u6587\u4ef6<br \/>\n\u251c\u2500README.md             README \u6587\u4ef6<br \/>\n\u2514\u2500think                 \u547d\u4ee4\u884c\u5165\u53e3\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u627e\u5230 <code>tp5\/public\/index.php<\/code> \u590d\u5236\u5230\u6839\u76ee\u5f55<code>tp5\/<\/code><br \/>\n\u6b64\u65f6\u76ee\u5f55\u5e94\u8be5\u5982\u6b64\uff1a<br \/>\ntp5<br \/>\n\u251c\u2500application           \u5e94\u7528\u76ee\u5f55<br \/>\n\u251c\u2500public                WEB\u76ee\u5f55\uff08\u5bf9\u5916\u8bbf\u95ee\u76ee\u5f55\uff09<br \/>\n\u251c\u2500thinkphp              \u6846\u67b6\u7cfb\u7edf\u76ee\u5f55<br \/>\n\u251c\u2500extend                \u6269\u5c55\u7c7b\u5e93\u76ee\u5f55<br \/>\n\u251c\u2500runtime               \u5e94\u7528\u7684\u8fd0\u884c\u65f6\u76ee\u5f55\uff08\u53ef\u5199\uff0c\u53ef\u5b9a\u5236\uff09<br \/>\n\u251c\u2500vendor                \u7b2c\u4e09\u65b9\u7c7b\u5e93\u76ee\u5f55\uff08Composer\u4f9d\u8d56\u5e93\uff09<br \/>\n\u251c\u2500build.php             \u81ea\u52a8\u751f\u6210\u5b9a\u4e49\u6587\u4ef6\uff08\u53c2\u8003\uff09<br \/>\n\u251c\u2500composer.json         composer \u5b9a\u4e49\u6587\u4ef6<br \/>\n\u251c\u2500LICENSE.txt           \u6388\u6743\u8bf4\u660e\u6587\u4ef6<br \/>\n\u251c\u2500README.md             README \u6587\u4ef6<br \/>\n\u251c\u2500<span style=\"red\">index.php            \u5165\u53e3\u6587\u4ef6<\/span><br \/>\n\u2514\u2500think                 \u547d\u4ee4\u884c\u5165\u53e3\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539<code>tp5\/index.php<\/code>\u5982\u4e0b\uff1a<\/p>\n<\/li>\n<\/ul>\n<pre class=\"lang:php decode:true\">\n    \/\/ \u5b9a\u4e49\u5e94\u7528\u76ee\u5f55\ndefine('APP_PATH', __DIR__ . '\/application\/');\n\/\/ \u52a0\u8f7d\u6846\u67b6\u5f15\u5bfc\u6587\u4ef6\nrequire __DIR__ . '\/thinkphp\/start.php';\n<\/pre>\n<ul>\n<li>\u4fee\u6539<code>thinkphp\/library\/think\/View.php<\/code>\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre class=\"lang:php decode:true\">\n    \/\/\u539f\u6765\u8fd9\u6837\n    \/\/'__STATIC__' => $root . '\/static', \n    \/\/\u2018__CSS__'    => $root . '\/static\/css',\n    \/\/'__JS__'     => $root . '\/static\/js',\n    \/\/\u6539\u6210\u8fd9\u6837\n    '__STATIC__' => $root . '\/public\/static',\n    '__CSS__'    => $root . '\/public\/static\/css',\n    '__JS__'     => $root . '\/public\/static\/js',\n<\/pre>\n<p>\u6b64\u65f6\u5e94\u8be5\u53ef\u4ee5\u8bbf\u95ee:<br \/>\n<code>localhost\/tp5<\/code><br \/>\n\u6b64\u94fe\u63a5\u7b49\u6548\u4e8e(\u4e0e3.2\u7c7b\u4f3c)<br \/>\n<code>localhost\/tp5\/index.php\/Index\/index<\/code><\/p>\n<h2><strong>\u589e\u52a0\u6a21\u5757<\/strong><\/h2>\n<p>\u6a21\u5757\u589e\u52a0\u6682\u65f6\u53ea\u77e5\u9053\u7528cmd\u7684\u65b9\u6cd5\uff0c\u5982\u6709\u65b0\u529e\u6cd5\u518d\u8865\u5145\uff0c\u4e00\u822c\u90fd\u662f\u4e00\u5f00\u59cbcmd\u7136\u540e\u540e\u9762\u65e0\u9650\u590d\u5236\u7c98\u8d34\u7684\u4e86\u3002<br \/>\n* \u4f7f\u7528cmd \u8fd0\u884cphp\u73af\u5883\uff0c\u6682\u65f6\u53ea\u77e5\u9053phpstudy\u7684\u529e\u6cd5\u3002<br \/>\n<a href=\"https:\/\/loveuhouse.cn\/wordpress\/wp-content\/uploads\/2017\/03\/\u641c\u72d7\u622a\u56fe20170318145235.png\"><img loading=\"lazy\" src=\"https:\/\/loveuhouse.cn\/wordpress\/wp-content\/uploads\/2017\/03\/\u641c\u72d7\u622a\u56fe20170318145235.png\" alt=\"\" width=\"461\" height=\"482\" class=\"alignnone size-full wp-image-562\" srcset=\"https:\/\/loveuhouse.cn\/wordpress\/wp-content\/uploads\/2017\/03\/\u641c\u72d7\u622a\u56fe20170318145235.png 461w, https:\/\/loveuhouse.cn\/wordpress\/wp-content\/uploads\/2017\/03\/\u641c\u72d7\u622a\u56fe20170318145235-287x300.png 287w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/a><br \/>\n* \u8fdb\u5165\u6587\u4ef6\u76ee\u5f55<\/p>\n<pre class=\"lang:default decode:true\">\n    cd WWW\/tp5\n<\/pre>\n<ul>\n<li>\u6267\u884c\u521b\u5efa\u6a21\u5757\u6307\u4ee4(\u521b\u5efaadmin\u6a21\u5757)<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">\n    php think build --module admin\n<\/pre>\n<h2><strong>\u589e\u52a0\u63a7\u5236\u5668<\/strong><\/h2>\n<p>\u63a7\u5236\u5668\u4e0d\u518d\u9700\u8981 <code>[\u63a7\u5236\u5668\u540d]Controller.class.php<\/code>\u7684\u540d\u5b57\u683c\u5f0f\uff0c\u76f4\u63a5\u4f7f\u7528<code>[\u63a7\u5236\u5668\u540d].php<\/code>\u5e76\u4e14\u5728<code>tp5\/application\/[\u6a21\u5757]\/controller<\/code>\u4e0b\u3002<br \/>\n\u4f8b\u5b50\uff1aIndex\u6a21\u5757\u4e0b\u65b0\u5efaUser\u63a7\u5236\u5668<br \/>\nindex<br \/>\n\u251c\u2500contorller           \u63a7\u5236\u5668\u76ee\u5f55<br \/>\n\u2502  \u251c\u2500Index.php        index\u63a7\u5236\u5668<br \/>\n\u2502  \u251c\u2500User.php        User\u63a7\u5236\u5668<br \/>\n...<\/p>\n<h3><strong>\u65b0\u5efa\uff1aUser.php (\u6ce8\u610f\u5927\u5199\u63a5\u5168\u90e8\u5c0f\u5199!!!)<\/strong><\/h3>\n<p>READ ME :\u6d4f\u89c8\u5668\u8bbf\u95ee\u63a7\u5236\u5668\u65f6<br \/>\n+ \u4f1a\u628a\u4efb\u4f55\u9a7c\u5cf0\u8bed\u6cd5\u5168\u90e8\u8f6c\u6362\u6210<code>Aaaaa<\/code> \u7684\u683c\u5f0f\uff0c\u6240\u4ee5\u6587\u4ef6\u5c3d\u91cf\u4ee5\u7b2c\u4e00\u4e2a\u5927\u5199\u63a5\u5168\u90e8\u5c0f\u5199\u6765\u547d\u540d\u3002<br \/>\n+ \u4f1a\u628a <code>_<\/code> \u540e\u9762\u4e00\u4e2a\u5355\u8bcd\u7406\u89e3\u4e3a\u5927\u5199 \u4f8b\u5982\uff1a<code>abc_d<\/code> \u5c31\u4f1a\u8bbf\u95ee<code>abcD.php<\/code>\u8fd9\u4e2a\u63a7\u5236\u5668\u3002<\/p>\n<pre class=\"lang:php decode:true\">\n<?php\nnamespace app\\index\\controller;\n\nclass User\n{\n    public function index()\n    {\n        return 'hellow user';\n    }\n}  \n?>\n<\/pre>\n<h5>NOTE\uff1anamespace \u662f\u7531 app&#91;\u6a21\u5757 (\u6ce8\u610f\u5c0f\u5199)]\\controller \u7ec4\u6210\u7684\uff0c\u5e76\u4e14Class [\u63a7\u5236\u5668\u540d]\u4e0e\u6587\u4ef6\u540d\u662f\u540c\u6b65\u7684<\/h5>\n<h3><strong>\u7ee7\u627fthink\\Controller \u7c7b<\/strong><\/h3>\n<p><code>use think\\Controller;<\/code><br \/>\n\u5982\u679c\u7ee7\u627f\u4e86think\\Controller\u7c7b\u7684\u8bdd\uff0c\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528think\\View\u53cathink\\Request\u7c7b\u7684\u65b9\u6cd5<\/p>\n<pre class=\"lang:php decode:true\">\n    public function index()\n    {\n        \/\/ \u83b7\u53d6\u5305\u542b\u57df\u540d\u7684\u5b8c\u6574URL\u5730\u5740\n        $this->assign('domain',$this->request->url(true));\n        return $this->fetch('index');\n    }\n<\/pre>\n<h2><strong>\u8fde\u63a5\u6570\u636e\u5e93<\/strong><\/h2>\n<p>\u5148\u8df3\u51fa3.2\u7684\u6570\u636e\u5e93\u601d\u7ef4\uff0ctp5\u63d0\u4f9b\u66f4\u591a\u5bf9\u591a\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u652f\u6301\u3002<\/p>\n<p>### <strong>\u65b9\u6cd51\uff1a\u5728admin\u4e2d\u65b0\u5efa <code>database.php<\/code> \u6587\u4ef6\uff1a<\/strong><\/p>\n<ul>\n<li>\u65b0\u5efaadmin\/database.php \u5e76 \u914d\u7f6e\u6570\u636e\u5e93<\/li>\n<\/ul>\n<h5>NOTE\uff1a\u524d\u7f00\u53ea\u6709\u5728Db::name('user')\u8fd9\u79cd\u4f7f\u7528\u60c5\u51b5\u4e0b\u6709\u6548\u3002<\/h5>\n<pre class=\"lang:php decode:true\">\n     <?php\n  return [\n    \/\/\u6570\u636e\u5e93\u914d\u7f6e-\u672c\u673a\n      \/\/ \u6570\u636e\u5e93\u7c7b\u578b\n      'type'        => 'mysql',\n      \/\/ \u670d\u52a1\u5668\u5730\u5740\n      'hostname'    => 'localhost',\n      \/\/ \u6570\u636e\u5e93\u540d\n      'database'    => 'datadeal',\n      \/\/ \u6570\u636e\u5e93\u7528\u6237\u540d\n      'username'    => 'root',\n      \/\/ \u6570\u636e\u5e93\u5bc6\u7801\n      'password'    => 'root',\n      \/\/ \u6570\u636e\u5e93\u7f16\u7801\u9ed8\u8ba4\u91c7\u7528utf8\n      'charset'     => 'utf8',\n      \/\/ \u6570\u636e\u5e93\u8868\u524d\u7f00\/\/\u524d\u7f00\u53ea\u6709\u5728Db::name('user')\u8fd9\u79cd\u60c5\u51b5\u4e0b\u6709\u6548\n      'prefix'      => '',\n      \/\/ \u6570\u636e\u5e93\u8c03\u8bd5\u6a21\u5f0f\n      'debug'       => false,\n  ];\n ?>\n <\/pre>\n<ul>\n<li>\u63a7\u5236\u5668\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c<br \/>\n##### NOTE\uff1a\u4e00\u5b9a\u8981\u8c03\u7528think\\Db\u7c7b\u3002<\/li>\n<\/ul>\n<pre class=\"lang:php decode:true\">\n        namespace app\\admin\\controller;\n        use Resportsale;\n        use think\\Db;\n\n        class Datatransfer\n        {\n                public function test()\n                {\n                    $shoplist=Db::query('select * from tao_orders_oneday_test where id=?',[1]);\n                    var_dump($shoplist);\n                }\n        }\n<\/pre>\n<h3><strong>\u65b9\u6cd52\uff1a\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b9a\u4e49\uff08\u591a\u7528\u4e8e\u591a\u6570\u636e\u5e93\u64cd\u4f5c\uff09\uff1a<\/strong><\/h3>\n<ul>\n<li>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff08admin\/config.php\uff09\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre class=\"lang:php decode:true\">\n<?php\n\/\/\u914d\u7f6e\u6587\u4ef6\nreturn [\n  'db_typeA'=>[\n    \/\/ \u6570\u636e\u5e93\u7c7b\u578b\n    'type'        => 'mysql',\n    \/\/ \u670d\u52a1\u5668\u5730\u5740\n    \/\/ 'hostname'    => 'rm-vy1g8bdkp31vzn2aj.mysql.rds.aliyuncs.com:3306',\n    'hostname'    => 'localhost:3306',\n    \/\/ \u6570\u636e\u5e93\u540d\n    \/\/ 'database'    => 'public_data',\n    'database'    => 'jiexiu',\n    \/\/ \u6570\u636e\u5e93\u7528\u6237\u540d\n    \/\/ 'username'    => 'jusr9mw7rezy',\n    'username'    => 'root',\n    \/\/ \u6570\u636e\u5e93\u5bc6\u7801\n    \/\/ 'password'    => 'jsb869_MINI',\n    'password'    => 'Janing351367',\n    \/\/ \u6570\u636e\u5e93\u7f16\u7801\u9ed8\u8ba4\u91c7\u7528utf8\n    'charset'     => 'utf8',\n    \/\/ \u6570\u636e\u5e93\u8868\u524d\u7f00\n    'prefix'      => 't_',\n    \/\/ \u6570\u636e\u5e93\u8c03\u8bd5\u6a21\u5f0f\n    'debug'       => false,\n  ]\n];\n?>\n<\/pre>\n<ul>\n<li>\u63a7\u5236\u5668\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/li>\n<\/ul>\n<pre class=\"lang:php decode:true\">\n        public function test()\n    {\n      $shoplist=Db::connect(\"db_typeA\")->query('select * from t_user where id=?',[1]);\n      var_dump($shoplist);\n    }\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u662f\u4e00\u4e2aTP3.2\u7684\u4e2d\u5ea6\u5f00\u53d1\u8005\u7684\u5b66\u4e60\u8bb0\u5f55 TP5 \u5b89\u88c5\u8fc7\u7a0b \u6682\u65f6\u53ea\u63d0\u4f9b \u5b98\u7f51\u4e0b\u8f7d \u5b8c\u6574\u7248\u7684\u5b89\u88c5\u65b9\u6cd5\uff0c\u5e76\u5c3d\u91cf\u8c03\u6574 &hellip; <a href=\"https:\/\/loveuhouse.cn\/wordpress\/?p=561\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">thinkphp 5 \u8e29\u5751\u8bb0\u5f55\u3010\u6301\u7eed\u66f4\u65b0217.03.25\u3011<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/561"}],"collection":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=561"}],"version-history":[{"count":9,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":586,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/561\/revisions\/586"}],"wp:attachment":[{"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loveuhouse.cn\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}