ѡ̳

 找回密码
 ע
搜索
查看: 276|回复: 0
打印 上一主题 下一主题

phpcms的 应用程序创建类 application.class.php

[复制链接]

789

主题

1158

帖子

4197

积分

Ա

Rank: 9Rank: 9Rank: 9

积分
4197
跳转到指定楼层
¥
发表于 2017-11-12 19:23:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
源码
  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. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | ע

本版积分规则

QQ|Archiver|ֻ|С|ѡ̳

GMT+8, 2026-5-2 07:27 , Processed in 0.079039 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表
0.0923s