zend framework 入口文件的编写
<?php
// 设置报错机制
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Asia/Shanghai');
// 设置包含路径
set_include_path('../application/controllers' . '.' . PATH_SEPARATOR . '../library/' . PATH_SEPARATOR . '../application/models' . PATH_SEPARATOR . get_include_path());
// 设置类的自动加载
require('Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
// 设置控制器
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('../application/controllers');
// 读取数据库配置
$config = new Zend_config_Ini('../application/config.ini','general');
$registry = Zend_Registry::getInstance();
$registry->set('config',$config);
// 建立DB对象实例
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
$db->query("SET NAMES utf8; ");
// 将DB对象实例写入注册表
Zend_Registry::set('db', $db);
// 缓存设置
// 缓存前端设置
$frontedOptions = array(
'lifeTime' => null,
'automatic_serialization' => true
);
// 缓存后端设置
$backendOptions = array(
'servers' => array('host'=>'localhost', 'port'=>'11211', 'persistent'=>true) //后端用memcached
//'cache_dir' => './tmp' //后端用File
);
//建立缓存对像实例
$cache = Zend_Cache::factory('Core', 'memcached', $frontedOptions, $backendOptions); //后端用memcached
//$cache = Zend_Cache::factory('Core', 'File', $frontedOptions, $backendOptions); //后端用File
Zend_Registry::set('cache', $cache);
$frontController->dispatch();
?>