 架构
架构原则:
一切都是对象,摒弃函数和
全局变量。
一切都有命名空间。
具体实现:
ROOT为站点根目录
代码片段
class="java">
#ROOT/.htaccess
#将请求从站点根目录转发到项目根目录
RewriteRule .* /com/kb/$0 [L]
#ROOT/com/kb/.htaccess
#约定ROOT/com/kb/app下为php文件所在目录,所有php请求转发到ROOT/com/kb/index.php
#其余目录绝无php文件
RewriteRule ^app.*\.php$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
所有php文件如下约定:
除视图模块php和ROOT/com/kb/index.php外,其余php文件每个文件对应一个类,命名空间、类名和文件路径保持一致,比如ROOT/com/kb/app/Xxx.php命名空间为\com\kb\app
//ROOT/com/kb/index.php代码片段
//实现类自动装载的方法之一
namespace {
    function __autoload($classname) {
        $class_path = \str_replace('\\', DIRECTORY_SEPARATOR, $classname);
        $file = __DIR__ . '/../../' . $class_path . '.php';
        if (\file_exists($file)) {
            require_once($file);
            if (\class_exists($classname, false)) {
                return true;
            }
        }
        return false;
    }
}
在此基础上实现完全的MVC模式。
ROOT/com/fall下为常用的工具类集合
  
  
  
    
      
        
           
- 大小: 30.3 KB