10)将地址换成常量

目录关系:

    

然后改动的地方展示:
    

    

    

 index.php代码展示:

    

 1 <?php
 2     /**
 3      * Created by PhpStorm.
 4      * User: Interact
 5      * Date: 2017/8/19
 6      * Time: 22:02
 7      */
 8     //确定分发参数
 9     //动作
10     define('CONTROLLER',isset($_GET['c'])?$_GET['c']:'zixunC');
11     define('ACTION',isset($_GET['a'])?$_GET['a']:'show');
12     define("PLATFORM",isset($_GET['p'])?$_GET['p']:'test');
13     //目录地址常量
14     define('ROOT_PATH',getcwd().'/');
15     define('APPLICATION_PATH',ROOT_PATH.'application'.'/');
16     define('FRAMEWORK_PATH',ROOT_PATH.'framework'.'/');
17     define('TEST_PATH',APPLICATION_PATH.'test'.'/');
18     define('CONTROLLER_PATH',TEST_PATH.'controller'.'/');
19     define('MODEL_PATH',TEST_PATH.'model'.'/');
20     define('VIEW_PATH',TEST_PATH.'view'.'/');
21     function userautoload($class_name){
22     
23 //        var_dump($class_name);
24         //先处理确定的(框架中的核心类)
25         // 类名与类文件映射数组
26         $framework_class_list = array(
27             // '类名' => '类文件地址'
28             'Controller' => FRAMEWORK_PATH.'Controller.php',
29             'Model' => FRAMEWORK_PATH.'Model.class.php',
30             'Factory' => FRAMEWORK_PATH.'Factory.class.php',
31             'MySQLDB' => FRAMEWORK_PATH.'MySQLDB.class.php',
32         ) ;
33 //        echo "走没走";
34         //判断是否为核心类
35         if (isset($framework_class_list[$class_name])) {
36             //是核心类
37             require $framework_class_list[$class_name];
38         }
39         //判断是否为可增加(控制器类,模型类)
40         //控制器类,截取后是个字符,匹配Controller
41         elseif (substr($class_name, -1) == 'C') {
42             // 控制器类, 当前平台下controller目录
43             require APPLICATION_PATH . PLATFORM . '/controller/' . $class_name . '.controller.class.php';
44         }
45         //模型类,截取后5个字符,匹配Model
46         elseif (substr($class_name, -5) == 'Model') {
47             // 模型类,当前平台下model目录
48             require APPLICATION_PATH . PLATFORM . '/model/' . $class_name . '.class.php';
49         }
50         
51     }
52     spl_autoload_register('userautoload');
53     
54     
55     
56     
57     require APPLICATION_PATH.PLATFORM.'/controller/'.CONTROLLER.'.controller.class.php';
58 $controlelr_name=CONTROLLER;
59 $controller=new $controlelr_name();
60 $action_name=ACTION;
61 $controller->$action_name();

 

posted @ 2017-08-20 13:44  小油菜1  阅读(290)  评论(0编辑  收藏  举报