一个简单的php mvc框架 的 代码说明,init.php 部分:
/project/init.php 负责初始化常量、全局变量、开发环境和数据库等配置信息,include library/ 里面 基本的函数库和class
<?php
Defined('APPLICATION_ENV') ? APPLICATION_ENV : (isset($_SERVER['APPLICATION_ENV']) ? Define('APPLICATION_ENV',$_SERVER['APPLICATION_ENV']) : Define('APPLICATION_ENV','production'));
Defined('ROOT_PATH') ? ROOT_PATH : Define('ROOT_PATH',dirname(__file__));
Define('LIBRARY_PATH',ROOT_PATH . "/library");
Define('CROND_PATH',ROOT_PATH . "/crond");
include_once(LIBRARY_PATH . "/function.php");
include_once(LIBRARY_PATH . "/action.php");
include_once(LIBRARY_PATH . "/db.php");
$_CONFIG = array();
if(APPLICATION_ENV == 'production'){
$hostname = 'server_production';
}
else{
$hostname = 'server_development';
}
//db连接配置
$_CONFIG['server_production']['db'] = array(
'host' => '127.0.0.1',
'dbname' => 'production',
'user' => 'username',
'passwd' => 'password',
);
$_CONFIG['server_development']['db'] = array(
'host' => '127.0.0.1',
'dbname' => 'development',
'user' => 'username',
'passwd' => 'password',
);
if(Defined('APPLICATION_PATH')){
include_once(APPLICATION_PATH . '/route.php');
}
//魔术引号关闭
//通过 php.ini 文件把这些选项设为 Off
//magic_quotes_sybase = Off
?>