加入收藏 | 设为首页 | 会员中心 | 我要投稿 驾考网 (https://www.jiakaowang.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

网站后台的phpCMS建构思路

发布时间:2023-03-27 10:56:38 所属栏目:教程 来源:
导读:PHPCMS后台框架实现思路

1.打开后台入口文件admin.PHP

header('location:index.PHP?m=admin');

跳转到index.PHP并且m=admin

2.打开index.PHP

define('PHPCMS_PATH', dirname(__FILE_
PHPCMS后台框架实现思路

1.打开后台入口文件admin.PHP

header('location:index.PHP?m=admin');

跳转到index.PHP并且m=admin

2.打开index.PHP

define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEParaTOR);

pc_base::creat_app();

定义了根目录,包含了框架的入口文件base.PHP,并且使用类静态方法creat_app()

3.打开框架入口文件base.PHP

define('IN_PHPCMS', true);

//PHPCMS框架路径

define('PC_PATH', dirname(__FILE__).DIRECTORY_SEParaTOR);

if(!defined('PHPCMS_PATH')) define('PHPCMS_PATH', PC_PATH.'..'.DIRECTORY_SEParaTOR);

//缓存文件夹地址

define('CACHE_PATH', PHPCMS_PATH.'caches'.DIRECTORY_SEParaTOR);

//主机协议

define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');

//当前访问的主机名

define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));

//来源

define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');

//系统开始时间

define('SYS_START_TIME', microtime());

//加载公用函数库

pc_base::load_sys_func('global');

pc_base::load_sys_func('extention');

pc_base::auto_load_func();

pc_base::load_config('system','errorlog') ? set_error_handler('my_error_handler') : error_reporting(E_ERROR | E_WARNING | E_PARSE);

//设置本地时差

function_exists('date_default_timezone_set') && date_default_timezone_set(pc_base::load_config('system','timezone'));

define('CHARSET' ,pc_base::load_config('system','charset'));

//输出页面字符集

header('Content-type: text/html; charset='.CHARSET);

//定义网站根路径

define('WEB_PATH',pc_base::load_config('system','web_path'));

//js 路径

define('JS_PATH',pc_base::load_config('system','js_path'));

//css 路径

define('CSS_PATH',pc_base::load_config('system','css_path'));

//img 路径

define('IMG_PATH',pc_base::load_config('system','img_path'));

//动态程序路径

define('APP_PATH',pc_base::load_config('system','app_path'));

//应用静态文件路径

define('PLUGIN_STATICS_PATH',WEB_PATH.'statics/plugin/');

if(pc_base::load_config('system','gzip') && function_exists('ob_gzhandler')) {

  ob_start('ob_gzhandler');

} else {

  ob_start();

}
  /**

   * 初始化应用程序

   */

  public static function creat_app() {

    return self::load_sys_class('application');

  }

  /**

   * 加载系统类方法

   * @param string $classname 类名

   * @param string $path 扩展地址

   * @param intger $initialize 是否初始化

   */

  public static function load_sys_class($classname, $path = '', $initialize = 1) {

      return self::_load_class($classname, $path, $initialize);

  }

  /**

   * 加载应用类方法

   * @param string $classname 类名

   * @param string $m 模块

   * @param intger $initialize 是否初始化

   */

  public static function load_app_class($classname, $m = '', $initialize = 1) {

    $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;

    if (empty($m)) return false;

    return self::_load_class($classname, 'modules'.DIRECTORY_SEParaTOR.$m.DIRECTORY_SEParaTOR.'classes', $initialize);

  }

 

  /**

   * 加载数据模型

   * @param string $classname 类名

   */

  public static function load_model($classname) {

    return self::_load_class($classname,'model');

  }

  /**

   * 加载类文件函数

   * @param string $classname 类名

   * @param string $path 扩展地址

   * @param intger $initialize 是否初始化

   */

  private static function _load_class($classname, $path = '', $initialize = 1) {

    static $classes = array();

    if (empty($path)) $path = 'libs'.DIRECTORY_SEParaTOR.'classes';

 

    $key = md5($path.$classname);

    if (isset($classes[$key])) {

      if (!empty($classes[$key])) {

        return $classes[$key];

      } else {

        return true;

      }

    }

    if (file_exists(PC_PATH.$path.DIRECTORY_SEParaTOR.$classname.'.class.PHP')) {

      include PC_PATH.$path.DIRECTORY_SEParaTOR.$classname.'.class.PHP';

      $name = $classname;

      if ($my_path = self::my_path(PC_PATH.$path.DIRECTORY_SEParaTOR.$classname.'.class.PHP')) {

        include $my_path;

        $name = 'MY_'.$classname;

      }

      if ($initialize) {

        $classes[$key] = new $name;

      } else {

        $classes[$key] = true;

      }

      return $classes[$key];

    } else {

      return false;

    }

  }

  /**

   * 加载系统的函数库

   * @param string $func 函数库名

   */

  public static function load_sys_func($func) {

    return self::_load_func($func);

  }

  /**

   * 自动加载autoload目录下函数库

   * @param string $func 函数库名

   */

  public static function auto_load_func($path='') {

    return self::_auto_load_func($path);

  }

  /**

   * 加载应用函数库

   * @param string $func 函数库名

   * @param string $m 模型名

   */

  public static function load_app_func($func, $m = '') {

    $m = empty($m) && defined('ROUTE_M') ? ROUTE_M : $m;

    if (empty($m)) return false;

    return self::_load_func($func, 'modules'.DIRECTORY_SEParaTOR.$m.DIRECTORY_SEParaTOR.'functions');

  }

  /**

   * 加载插件类库

   */

  public static function load_plugin_class($classname, $identification = '' ,$initialize = 1) {

    $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;

    if (empty($identification)) return false;

    return pc_base::load_sys_class($classname, 'plugin'.DIRECTORY_SEParaTOR.$identification.DIRECTORY_SEParaTOR.'classes', $initialize);

  }

  /**

   * 加载插件函数库

   * @param string $func 函数文件名称

   * @param string $identification 插件标识

   */

  public static function load_plugin_func($func,$identification) {

    static $funcs = array();

    $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;

    if (empty($identification)) return false;

    $path = 'plugin'.DIRECTORY_SEParaTOR.$identification.DIRECTORY_SEParaTOR.'functions'.DIRECTORY_SEParaTOR.$func.'.func.PHP';

    $key = md5($path);

    if (isset($funcs[$key])) return true;

    if (file_exists(PC_PATH.$path)) {

      include PC_PATH.$path;

    } else {

      $funcs[$key] = false;

      return false;

    }

    $funcs[$key] = true;

    return true;

  }

  /**

   * 加载插件数据模型

   * @param string $classname 类名

   */

  public static function load_plugin_model($classname,$identification) {

    $identification = empty($identification) && defined('PLUGIN_ID') ? PLUGIN_ID : $identification;

    $path = 'plugin'.DIRECTORY_SEParaTOR.$identification.DIRECTORY_SEParaTOR.'model';

    return self::_load_class($classname,$path);

  }


  /**

   * 加载函数库

   * @param string $func 函数库名

   * @param string $path 地址

   */

  private static function _load_func($func, $path = '') {

    static $funcs = array();

    if (empty($path)) $path = 'libs'.DIRECTORY_SEParaTOR.'functions';//默认函数地址在lib function

    $path .= DIRECTORY_SEParaTOR.$func.'.func.PHP';

    $key = md5($path);

    if (isset($funcs[$key])) return true;

    if (file_exists(PC_PATH.$path)) {

      include PC_PATH.$path;

    } else {

      $funcs[$key] = false;

      return false;

    }

    $funcs[$key] = true;

    return true;

(编辑:驾考网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章