2008-7-25 15:58
yhl_amerry
ZF中Smarty应用问题
各位ZF前辈,帮帮忙,非常感谢!
我从
[url]http://www.phpeye.com/bbs/thread-53-1-1.html[/url]
上面学习,不知道他里面的那个Custom_View_Smarty怎么配置
=============================================
我的文件架构见附件。
问题:
1.怎么配置smarty在ZF中应用?即这个文件 Custom_View_Smarty怎么写?
2.$smarty->display()怎么指向对应的前后台网页模板,分别对应到admin/views、default/views.
=============================================
我的接口文件是这样写的:
//index.php
[color=Blue]<?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
//目录分隔符号
$ds = DIRECTORY_SEPARATOR;
//路径分隔符号
$ps = PATH_SEPARATOR;
$ABS_ROOT_PATH = realpath(dirname(__FILE__));
$REL_ROOT_PATH = substr($_SERVER['PHP_SELF'], 0 , strpos($_SERVER['PHP_SELF'],'/index.php'));
set_include_path('.'.PATH_SEPARATOR.'./library'
.PATH_SEPARATOR.'./application/models/'
.PATH_SEPARATOR.get_include_path());
require('Zend/Loader.php');
//自动加载类
function __autoload($class){
Zend_Loader::loadClass($class);
}
//数据库配置
$dbParams = new Zend_Config_Ini('./application/config/database.ini','DB_ART');
$db = Zend_Db::factory($dbParams->adapter,$dbParams->toArray());
$db->query("set names {$dbParams->charset};");
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db',$db);
//SMARTY配置
$smartyParams = new Zend_Config_Ini('./application/config/smarty.ini', 'Smarty');
$smarty = new Custom_View_Smarty($smartyParams->toArray());
Zend_Registry::set('smarty',$smarty);
//初始控制器
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(array(
'default' => './application/modules/default/controllers',
'admin' => './application/modules/admin/controllers'
));
$frontController->addModuleDirectory('./application/modules');
$frontController->setParam('noViewRenderer',true);
$frontController->setBaseUrl($REL_ROOT_PATH);
try{
$frontController->dispatch();
}catch(Zend_Controller_Dispatcher_Exception $e){
$frontController->getResponse()->setHttpResponseCode(404);
$frontController->getResponse()->__toString();
}[/color]
----------------------------------------------------------------------------
//smarty配置文件smarty.ini
[Smarty]
left_delimiter="<{"
right_delimiter="}>"
template_dir="./application/modules/admin/views"
compile_dir="./application/modules/admin/templates_c"
[[i] 本帖最后由 yhl_amerry 于 2008-7-25 16:01 编辑 [/i]]