{"id":423752,"date":"2021-04-03T11:09:05","date_gmt":"2021-04-03T03:09:05","guid":{"rendered":"http:\/\/4563.org\/?p=423752"},"modified":"2021-04-03T11:09:05","modified_gmt":"2021-04-03T03:09:05","slug":"%e8%af%b7%e9%97%ae%ef%bc%8c%e8%bf%99%e5%87%a0%e5%8f%a5%e7%ae%80%e5%8d%95%e7%9a%84%e4%bb%a3%e7%a0%81%e8%bf%99%e6%a0%b7%e5%86%99%e6%9c%89%e4%bb%80%e4%b9%88%e9%97%ae%e9%a2%98%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=423752","title":{"rendered":"\u8bf7\u95ee\uff0c\u8fd9\u51e0\u53e5\u7b80\u5355\u7684\u4ee3\u7801\u8fd9\u6837\u5199\u6709\u4ec0\u4e48\u95ee\u9898\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u95ee\uff0c\u8fd9\u51e0\u53e5\u7b80\u5355\u7684\u4ee3\u7801\u8fd9\u6837\u5199\u6709\u4ec0\u4e48\u95ee\u9898\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wfdaj <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>public static function render($file, $data = null)     {         $file_path = dirname(__DIR__) . \"\/views\/{$file}.php\";          \/\/ \u5982\u679c\u7ed9\u5b9a\u6587\u4ef6\u540d\u4e0d\u5b58\u5728\u6216\u4e0d\u53ef\u8bfb         if (!is_readable($file_path)) {             throw new Exception(\"\u627e\u4e0d\u5230\u6a21\u677f\u6587\u4ef6\uff1a{$file_path}\u3002\");         }          \/\/ \u5982\u679c\u662f\u6570\u7ec4\u5c31\u5408\u5e76         if (is_array($data)) {             array_merge($data);         }          extract($data);          include $file_path;     } <\/code><\/pre>\n<p>\u7136\u540e\u6a21\u677f\u4e2d\u8fd9\u6837\u4f7f\u7528\uff1a<\/p>\n<pre><code>$a = 1; View::render('home\/index', compact('a')); <\/code><\/pre>\n<p>\u6211\u4e0d\u6e05\u695a\u8be5\u5982\u4f55\u68c0\u67e5\u662f\u5426\u6709\u5b89\u5168\u95ee\u9898       <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5627582\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : eason1874 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             array_merge \u90a3\u884c\u6709\u7528\uff1f\u770b\u5f97\u6211\u6709\u70b9\u6000\u7591\u6211\u5bf9 PHP \u7684\u4e86\u89e3\u4e86\u3002<\/p>\n<p>extract \u53ef\u4ee5\u5728\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u5165 EXTR_SKIP \u4e0d\u8986\u76d6\u5df2\u5b58\u5728\u7684\u53d8\u91cf\u3002<\/p>\n<p>\u6a21\u677f\u53d8\u91cf\u4f60\u4e0d\u8be5\u76f4\u63a5\u4f20\u5165\u7528\u6237\u8f93\u5165\uff0c\u4f60\u8981\u5148\u8fc7\u6ee4\u597d\u518d\u4f20\u5165\uff0c\u6240\u4ee5\u5b89\u5168\u8fc7\u6ee4\u4e5f\u4e0d\u5728\u8fd9\u91cc\u8fc7\u6ee4\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627583\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shenjinpeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6570\u7ec4\u5408\u5e76\u4e86\u4e2a\u5bc2\u5bde                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627584\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wfdaj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @eason1874 \u611f\u8c22\u56de\u590d\u3002<br \/>array_merge \u6211\u4ee5\u4e3a\u5982\u679c\u4f20\u5165\u591a\u4e2a\u6570\u7ec4\u9700\u8981\u5408\u5e76\u6210\u4e00\u4e2a\u5462\uff1b<br \/>EXTR_SKIP \u786e\u5b9e\u53ef\u4ee5\uff1b<br \/>\u662f\u7684\uff0c\u6211\u662f\u521a\u5b66\uff0c\u5148\u5b9e\u73b0\u80fd\u6b63\u5e38\u663e\u793a\u9875\u9762\uff0c\u7136\u540e\u5b66\u4e60\u8fc7\u6ee4\u8f93\u5165\u3002\u518d\u6b21\u611f\u8c22\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627585\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wfdaj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @shenjinpeng \u5e94\u8be5\u628a\u4ee3\u7801\u653e\u5230 github \u4e0a\uff0c\u8d77\u540d\u662f \u201cphp \u65b0\u624b\u5e38\u89c1\u9519\u8bef\u7528\u6cd5\u5b9e\u4f8b\u201d                                                             <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627586\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : faqqcn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5355\u4e2a\u503c array_merge \u7684\u4f5c\u7528\u7b49\u540c\u4e8e array_values                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627587\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : faqqcn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @faqqcn \u8865\u5145\u4e00\u53e5\uff0c\u201c\u6570\u5b57\u952e\u7684\u60c5\u51b5\u4e0b\u201d\uff0c\u56e0\u4e3a array_merge \u4e5f\u4f1a\u91cd\u7f6e\u6570\u5b57\u952e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627588\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imdong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @faqqcn \u8fd9\u4e2a\u8fd8\u771f\u6ce8\u610f\u8fc7\uff0c\u770b\u4e86\u4e0b\u6587\u6863\u201c\u6570\u5b57\u7d22\u5f15\u201d\u786e\u5b9e\u4f1a\u91cd\u65b0\u6392\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u9700\u8981 extract \u7684\u5927\u6982\u7387\u662f\u5173\u8054\u6570\u7ec4\u4e86\uff0c\u6240\u4ee5\u771f\u7684\u5c31 array_merge \u4e86\u4e2a\u5bc2\u5bde\u3002<\/p>\n<p>\u800c\u4e14\u5c31\u7b97\u7d22\u5f15\u5408\u5e76\u4e86\uff0c\u7531\u4e8e\u8c03\u7528\u4e0d\u662f\u5f15\u7528\u7684\uff0c\u800c\u8fd4\u56de\u503c\u6ca1\u6709\u63a5\u6536\u3002<\/p>\n<p>\u5bc2\u5bde\u65f6\u7684\u7231\uff0c\u5230\u5e95\u7231\u7684\u8be5\u4e0d\u8be5\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627589\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imdong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53e6\u5916\u8865\u5145\u56de\u7b54\u4e3b\u7684\u95ee\u9898:<\/p>\n<p>\u7b2c\u4e00\u4e2a\u6f0f\u6d1e\uff1a\u5982\u679c\u6784\u9020\u51fa $file = &#8220;..\/..\/upload\/image&#8221;<\/p>\n<p>\u5e76\u4e14\u6070\u5de7\u8fd9\u4e2a\u76ee\u5f55\u662f\u4e0a\u4f20\u76ee\u5f55\uff0c\u5c31\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0 include \u7528\u6237\u4e0a\u4f20\u7684\u6587\u4ef6\uff0c\u800c\u5bfc\u81f4\u4e0a\u4f20\u540e\u95e8\u88ab\u5229\u7528\u3002<\/p>\n<p>\u7136\u540e extract \u8fd9\u4e2a\u7684\u8bdd\uff0c\u5e94\u8be5\u95ee\u9898\u4e0d\u5927\uff0c\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u8fd9\u4e48\u641e\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5627590\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : faqqcn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imdong \u8fd9\u4e2a\u53ef\u4ee5\u7528 realpath \u5904\u7406\u540e\u518d\u8fc7\u6ee4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u95ee\uff0c\u8fd9\u51e0\u53e5\u7b80\u5355\u7684\u4ee3\u7801\u8fd9\u6837\u5199\u6709\u4ec0\u4e48&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/423752"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=423752"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/423752\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=423752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=423752"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=423752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}