今天我们来讲一下关于php mvc模板的zend使用方法与配置实例,这是一款从zend加载 config文件到加载数据库 getinstance()方法用来获取前端控制器实例 加载smarty模板插件等简单的配置方法。
*/
//指明引用文件的路径
set_include_path('.' .
path_separator . './libary/'. //指定zend所在目录
path_separator . './application/models/'. //指定model所在目录
path_separator . './libary/smarty/'.
path_separator . get_include_path());
//必须手动加载loader.php
include "zend/loader.php";
zend_loader::registerautoload();
//加载数据库配置文件
//zend/config/ini.php
$config = new zend_config_ini ('./application/config.ini', 'general');
$registry = zend_registry::getinstance();
$registry->set('config', $config);
//
$db = zend_db::factory ($config->db);
$db->query('set names gbk');
zend_db_table::setdefaultadapter($db);
//getinstance()方法用来获取前端控制器实例
$frontcontroller = zend_controller_front::getinstance();
//指定模块目录
$frontcontroller->addmoduledirectory('./application');
//加载smarty模板插件
$frontcontroller->registerplugin(new plugin_myplugin());
//zend布局应用
//$options = array("layout"=>"head","layoutpath"=>"/layouts", 'contentkey' => 'content');
//$layout = new zend_layout($options);
//设置模板后缀名
$viewrenderer = zend_controller_action_helperbroker::getstatichelper('viewrenderer');
$viewrenderer->setviewsuffix('php');
//抛出异常
$frontcontroller->throwexceptions(true);
//开始运行程序
$frontcontroller->dispatch();
?>