MVC路径常量

目录地址常量

项目中,使用目录常量的形式,管理项目中所需要的地址,通过拼凑,连接操作形成某个位置。

使用目录常量

作为项目的初始化阶段,开始初始化目录常量:

先确定根目录,再拼凑确定子目录:

Index.php

Tip:函数getCWD()可以用来获得当前工作目录。Current Working Directory

define('ROOT_PATH',getCWE().'/');

define('APPLICATION_PATH',ROOT_PATH.'application/');

define('FRAMEWORK_PATH',ROOT_PATH.'frameworh/');

 

$default_platfrom = 'test';

define('PLATFROM',isset($_GET['p']) ? $_GET['p'] : $default_platfrom );

$default_controller = 'match';

define('CONTROLLER',isset($_GET['c']) ? $_GET['c'] : $default_platfrom );

$default_action = 'list';

define('ACTION',isset($_GET['a']) ? $_GET['a'] : $default_platfrom );

 

define('CURRENT_CONTROLLER_PATH',APPLICATION_PATH.PLATFROM.'/controller/');

define('CURRENT_MODEL_PATH',APPLICATION_PATH.PLATFROM.'/model/');

define('CURRENT_VIEW_PATH',APPLICATION_PATH.PLATFROM.'/view/');

所有的涉及到文件地址的都有常量来完成:

  function userAutoload($class_name){

      $framework_class_list = array(

        'Controller' => FRAMEWORK_PATH.'Controller.class.php',

        'Model' => FRAMEWORK_PATH.'Model.class.php',

        'Factroy' => FRAMEWORK_PATH.'Factroy.class.php',

        'MySQLDB' => FRAMEWORK_PATH.'MySQLDB.class.php',

      )

      if(isset($framework_class_list[$class_name])){

        require $framework_class_list[$class_name];

      }else if(substr($class_name,-10) == 'Controller'){

        require CURRENT_CONTROLLER_PATH.$class_name.'.class.php';

      }else if(substr($class_name,-5) == 'Model'){

        require CURRENT_MODEL_PATH.$class_name.'.class.php';

      }

    }

   html文件

    require CURRENT_VIEW_PATH.'match.html';

posted @ 2019-06-04 09:53  zsyzsyzsyzsyzsy  阅读(174)  评论(0编辑  收藏  举报