Home > php教程 > php手册 > php zend 配置,数据库加,模板引擎设置

php zend 配置,数据库加,模板引擎设置

WBOY
Release: 2016-05-25 16:42:48
Original
1344 people have browsed it

今天我们来讲一下关于php mvc模板的zend使用方法与配置实例,这是一款从zend加载 config文件到加载数据库 getinstance()方法用来获取前端控制器实例 加载smarty模板插件等简单的配置方法,实例代码如下:

<?php
//指明引用文件的路径
set_include_path(&#39;.&#39; . path_separator . &#39;./libary/&#39; . //指定zend所在目录
path_separator . &#39;./application/models/&#39; . //指定model所在目录
path_separator . &#39;./libary/smarty/&#39; . path_separator . get_include_path());
//必须手动加载loader.php
include "zend/loader.php";
zend_loader::registerautoload();
//加载数据库配置文件
//zend/config/ini.php
$config = new zend_config_ini(&#39;./application/config.ini&#39;, &#39;general&#39;);
$registry = zend_registry::getinstance();
$registry->set(&#39;config&#39;, $config);
//
$db = zend_db::factory($config->db);
$db->query(&#39;set names gbk&#39;);
zend_db_table::setdefaultadapter($db);
//getinstance()方法用来获取前端控制器实例
$frontcontroller = zend_controller_front::getinstance();
//指定模块目录
$frontcontroller->addmoduledirectory(&#39;./application&#39;);
//加载smarty模板插件
$frontcontroller->registerplugin(new plugin_myplugin());
//zend布局应用
//$options = array("layout"=>"head","layoutpath"=>"/layouts", &#39;contentkey&#39; => &#39;content&#39;);
//$layout = new zend_layout($options);
//设置模板后缀名//开源代码phprm.com
$viewrenderer = zend_controller_action_helperbroker::getstatichelper(&#39;viewrenderer&#39;);
$viewrenderer->setviewsuffix(&#39;php&#39;);
//抛出异常
$frontcontroller->throwexceptions(true);
//开始运行程序
$frontcontroller->dispatch();
Copy after login


永久地址:

转载随意~请带上教程地址吧^^

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template