Bug can at anywhere,Can you find it?
由zendframework撰写的日志
ZendFramework1.97 和 Smarty 结合并用的方法
一 22nd
网上搜了一堆结合的方法都是 ZF1.8 以下的..自己研究了2天终于成功了。记录一下..
目录结构是Zend Studio – 7.1.1 自建生成的,其中 template 和 templates 是我自己加上去给Smarty用的,也可以说是替换ZF 的View层。如下图
第一步 配置application.ini
把 resources.frontController.noViewRenderer = 1 加到 production 里,然后在staging : production 里面加上smarty的配置信息
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.noViewRenderer = 1
[staging : production]
smarty.class_path = "Smarty/Smarty.class.php"
smarty.left_delimiter = "{"
smarty.right_delimiter = "}"
smarty.template_dir =APPLICATION_PATH "/template/"
smarty.compile_dir =APPLICATION_PATH "/templates_c/"
smarty.cache_dir = APPLICATION_PATH "/cache/"
smarty.cache_lifetime = 600
smarty.caching = 0
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
第二步 修改Bootstrap.php
添加下面的代码
public function _initView(){
$config = new Zend_Config_Ini(APPLICATION_PATH. '/configs/application.ini', 'staging');
require_once $config->smarty->class_path;
$smarty = new Smarty();
$smarty->left_delimiter = $config->smarty->left_delimiter;
$smarty->right_delimiter = $config->smarty->right_delimiter;
$smarty->template_dir = $config->smarty->template_dir;
$smarty->compile_dir = $config->smarty->compile_dir;
$smarty->cache_dir = $config->smarty->cache_dir;
$smarty->cache_lifetime = $config->smarty->cache_lifetime;
$smarty->caching = $config->smarty->caching;
Zend_Registry::set('smarty', $smarty);
}
第三步 在 controller 测试
添加下面的代码
public function indexAction()
{
$template='test/test.html';
$this->smarty = Zend_Registry::get('smarty');
$this->smarty->assign('test', 'iamkane');
$this->smarty->display($template);
}
