ѡ̳

标题: phpcms的 应用程序创建类 application.class.php [打印本页]

作者: admin    时间: 2017-11-12 19:23
标题: phpcms的 应用程序创建类 application.class.php
源码
  1. <?php
  2. /**
  3. *  application.class.php PHPCMS应用程序创建类
  4. *
  5. * @copyright                        (C) 2005-2010 PHPCMS
  6. * @license                                http://www.phpcms.cn/license/
  7. * @lastmodify                        2010-6-7
  8. */
  9. class application {
  10.        
  11.         /**
  12.          * 构造函数
  13.          */
  14.         public function __construct() {
  15.                 $param = pc_base::load_sys_class('param');
  16.                 define('ROUTE_M', $param->route_m());
  17.                 define('ROUTE_C', $param->route_c());
  18.                 define('ROUTE_A', $param->route_a());
  19.                 $this->init();
  20.         }
  21.        
  22.         /**
  23.          * 调用件事
  24.          */
  25.         private function init() {
  26.                 $controller = $this->load_controller();
  27.                 if (method_exists($controller, ROUTE_A)) {
  28.                         if (preg_match('/^[_]/i', ROUTE_A)) {
  29.                                 exit('You are visiting the action is to protect the private action');
  30.                         } else {
  31.                                 call_user_func(array($controller, ROUTE_A));
  32.                         }
  33.                 } else {
  34.                         exit('Action does not exist.');
  35.                 }
  36.         }
  37.        
  38.         /**
  39.          * 加载控制器
  40.          * @param string $filename
  41.          * @param string $m
  42.          * @return obj
  43.          */
  44.         private function load_controller($filename = '', $m = '') {
  45.                 if (empty($filename)) $filename = ROUTE_C;
  46.                 if (empty($m)) $m = ROUTE_M;
  47.                 $filepath = PC_PATH.'modules'.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR.$filename.'.php';

  48.                 //echo $filepath;
  49.                 if (file_exists($filepath)) {
  50.                         $classname = $filename;
  51.                         include $filepath;
  52.                         if ($mypath = pc_base::my_path($filepath)) {
  53.                                 $classname = 'MY_'.$filename;
  54.                                 include $mypath;
  55.                         }
  56.                         if(class_exists($classname)){
  57.                                 return new $classname;
  58.                         }else{
  59.                                 exit('Controller does not exist.');
  60.                         }
  61.                 } else {
  62.                         exit('Controller does not exist.');
  63.                 }
  64.         }
  65. }
复制代码







欢迎光临 ѡ̳ (http://www.sunminxuan.cn/bbs/) Powered by Discuz! X3.4