zoukankan      html  css  js  c++  java
  • TP框架,根据当前应用状态对应的配置文件

      index.php

    define('APP_STATUS','website');

    /ThinkPHP/Library/Think/Dispatcher.class.php

        /**
         * 应用程序初始化
         * @access public
         * @return void
         */
        static public function start() {
      ......
    // 读取当前应用状态对应的配置文件
          if(APP_STATUS && is_file(CONF_PATH.APP_STATUS.CONF_EXT)){
            echo CONF_PATH.APP_STATUS.CONF_EXT;exit();
              C(include CONF_PATH.APP_STATUS.CONF_EXT);   //包含文件为"./Apps/Common/Conf/website.php",先看website.php
    
          }  
      }

    项目目录/Apps/Common/Conf/website.php

    <?php return M("Config")->getField("config_name,config_value"); 

    website.php用M方法,获取表config的配置记录,当然也可以不连接数据库,直接返回数组

    /ThinkPHP/Common/functions.php

    function C($name=null, $value=null,$default=null) {
        static $_config = array();
        // 无参数时获取所有
        if (empty($name)) {
            return $_config;
        }
        // 优先执行设置获取或赋值
        if (is_string($name)) {
            if (!strpos($name, '.')) {
                $name = strtoupper($name);
                if (is_null($value))
                    return isset($_config[$name]) ? $_config[$name] : $default;
                $_config[$name] = $value;
                return null;
            }
            // 二维数组设置和获取支持
            $name = explode('.', $name);
            $name[0]   =  strtoupper($name[0]);
            if (is_null($value))
                return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : $default;
            $_config[$name[0]][$name[1]] = $value;
            return null;
        }
        // 批量设置
        if (is_array($name)){//走这一步,因为实参是数组
            $_config = array_merge($_config, array_change_key_case($name,CASE_UPPER));
            return null;
        }
        return null; // 避免非法参数
    }

    所以,index.php中的APP_PATH决定了加载哪一个配置文件.

  • 相关阅读:
    StatusBar
    iOS开发UI篇-UITabBarController简单介绍
    iOS最全梳理
    UITabbarController的UITabbarItem(例:"我的")点击时,判断是否登录
    iOS APP 发布上架流程
    IOS开发
    IT教育课程考评系统开发-26
    IT教育课程考评系统开发-25
    2020100201-1
    IT教育课程考评系统开发-24
  • 原文地址:https://www.cnblogs.com/ch459742906/p/6085208.html
Copyright © 2011-2022 走看看