Uninote
Uninote
用户根目录
每日点滴

<!DOCTYPE html> <html><head><meta http-equiv='Content-Type' content='text/html; charset=utf8'><title>custom config;user/my config</title> <script> var g_resRoot = '../../__res/'; var g_json_outline = '{"children":[{"children":[],"level":1,"lvNumber":"1","text":"数组覆盖方式:"},{"children":[],"level":1,"lvNumber":"2","text":"普通的全局变量覆盖方式:"},{"children":[],"level":1,"lvNumber":"3","text":"全局变量+数据配置方式:"},{"children":[],"level":1,"lvNumber":"4","text":"nodejs"}],"level":0,"lvNumber":"","text":"custom config;user/my config"}'; </script> <link rel='stylesheet' type='text/css' href='../../__res/common.css'><style>.s0{color:#0000ff;} .s1{color:#000000;} .s2{color:#c80000;} .s3{color:#000000;} .s4{color:#000000;} .s5{color:#000000;} .s6{color:#000080;} .s7{color:#660e7a;} .s8{color:#008000;} .s9{color:#000000;} </style> </head><body> <script src='../../__res/util.js'></script><div id='outline'> <li><a href='#ol_0' style='font-weight:bold; font-size:22px'>custom config;user/my config</a></li> <li> <a href='#ol_1' >数组覆盖方式:</a></li> <li> <a href='#ol_2' >普通的全局变量覆盖方式:</a></li> <li> <a href='#ol_3' >全局变量+数据配置方式:</a></li> <li> <a href='#ol_4' >nodejs</a></li> </div>

<t id='568deb9a-5ee4-401a-b324-6d9f5d0fcacf'> <pre class='tnd_head'>lv1=programming lv2= type=</pre> <pre id='ol_0' class='title'>custom config;user/my config</pre> <pre><d class='s0'>ig</d><d class='s1'></d></pre> <pre><d class='s1'>通用原则(最小化工作量原则):</d></pre> <pre><d class='s1'>1 通用的配置进git仓库,不要让每次部署都去做相同的配置</d></pre> <pre><d class='s1'>2 提供覆盖配置的文件,此文件可以不存在。</d><d class='s2'>注意,一定要用相对于__DIR__的路径</d><d class='s1'></d></pre> <pre><d class='s1'></d></pre> <pre><d class='s1'>即,绝大多是情况下,用默认配置即可。</d></pre> <pre><d class='s1'></d></pre> <pre><d class='s3'>tips:如果发现重写好像不对,先直接在原始地方改,确认配置正确</d></pre> <pre><d class='s1'></d></pre> <h2 id='ol_1'>数组覆盖方式:</h2> <pre><d class='s1'>$db = require DIR . '/db.php';</d></pre> <pre><d class='s1'>if (is_file(DIR . "/local_db.php")) {</d></pre> <pre><d class='s1'> $db = array_merge($db, require_once DIR . '/local_db.php'); // 自定义配置放后面</d></pre> <pre><d class='s1'>}</d></pre> <pre><d class='s1'>// local_db.php:</d></pre> <pre><d class='s1'>return [</d></pre> <pre><d class='s1'> 'password' => 'root',</d></pre> <pre><d class='s1'>];</d></pre> <pre><d class='s1'></d></pre> <h2 id='ol_2'>普通的全局变量覆盖方式:</h2> <pre><d class='s1'>$name = "a";</d></pre> <pre><d class='s1'>$path_my = DIR . "/common.my.php";</d></pre> <pre><d class='s1'>if (is_file($path_my)) {</d></pre> <pre><d class='s1'> require_once $path_my;</d></pre> <pre><d class='s1'>}</d></pre> <pre><d class='s1'></d></pre> <pre><d class='s1'>// common.my.php:</d></pre> <pre><d class='s1'>$name = "b";</d></pre> <pre><d class='s1'></d></pre> <h2 id='ol_3'>全局变量+数据配置方式:</h2> <pre><d class='s1'>$config["port"] = "3306";</d></pre> <pre><d class='s1'>$path_my = DIR . '/config.my.php';</d></pre> <pre><d class='s1'>if (file_exists($path_my)) {</d></pre> <pre><d class='s1'> require($path_my);</d></pre> <pre><d class='s1'>}</d></pre> <pre><d class='s1'></d></pre> <pre><d class='s1'>// config.my.php</d></pre> <pre><d class='s1'>$config["port"] = "3306";</d></pre> <pre><d class='s4'></d></pre> <h2 id='ol_4'>nodejs</h2> <pre><d class='s5'>注意,一个使用当前路径,一个是相对于自身的路径:</d></pre> <pre><d class='s6'>var </d><d class='s7'>fs </d><d class='s4'>= </d><d class='s7'>require</d><d class='s4'>(</d><d class='s8'>"fs"</d><d class='s4'>);</d></pre> <pre><d class='s6'>if </d><d class='s4'>(</d><d class='s7'>fs</d><d class='s4'>.existsSync(</d><d class='s8'>'config/index.my.js'</d><d class='s4'>)) {</d></pre> <pre><d class='s4'> </d><d class='s7'>myconfig </d><d class='s4'>= </d><d class='s7'>require</d><d class='s4'>(</d><d class='s8'>'./index.my.js'</d><d class='s4'>)</d></pre> <pre><d class='s4'>}</d></pre> <pre><d class='s1'></d></pre> <pre><d class='s9'><a href='..\mynote/mynote-front.html#11fccc13-f50f-40ff-86af-4202f5a4a100'>my config mynote-front </a></d></pre> <pre><d class='s4'></d></pre> </t> </d></pre> </body></html>

cmd_admin

dbdiffer

点赞(0) 阅读(70) 举报
目录
标题