Home  >  Article  >  php教程  >  PHP留言板 原生MVC架构+MONGODB数据库

PHP留言板 原生MVC架构+MONGODB数据库

WBOY
WBOYOriginal
2016-06-06 19:33:171218browse

原生态的PHPMVC架构,需提前安装mongodb MongoDB /** * 入口文件 * * @version $Id: index.php 2014-3-12 下午2:27:11 zhangzw $ */// 加载路径$dirpath = array(get_include_path(), 'class', 'model', 'config');set_include_path( implode(PATH_SEPARATOR,

原生态的PHP MVC架构, 需提前安装  mongodb MongoDB
/**
 * 入口文件
 *
 * @version $Id: index.php   2014-3-12 下午2:27:11 zhangzw $
 */

// 加载路径
$dirpath = array(get_include_path(), 'class', 'model', 'config');

set_include_path( implode(PATH_SEPARATOR, $dirpath) );

// 自动加载调用类
class ClassLoader{

	/**
	 * 加载类名称
	 * @param string $class_name
	 */
	public static function class_loader($class_name){
		$class_name = strtolower($class_name);
		
		$search = 'cls';
		if( strpos( $class_name, $search) > 0 ){
			$file = str_replace($search, '', $class_name).'_'.$search.'.php';			
			require_once $file;
		}
	}

	/**
	 * 加载模型类
	 * @param string $model_name
	 */
	public static function model_loader($model_name){

		if(strpos( strtolower($model_name), 'model') > 0){
			$file = 'model_'.strtolower($model_name).'.php';
			require_once $file;
		}

	}


}

// 加载类文件
spl_autoload_register(array('ClassLoader', 'class_loader'));

// 加载模型文件
spl_autoload_register(array('ClassLoader', 'model_loader'));

// 初始化
$core = CoreCls::instance();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn