欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

小弟我用ZF框整合smarty,出了点异常,请各位帮忙看下了

程序员文章站 2022-05-05 21:54:45
...
我用ZF框整合smarty,出了点错误,请各位帮忙看下了。
我用ZF框整合smarty,出了点错误,请各位帮忙看下了,貌似是路径的错误。
我先是在分别创建了application/views/templates和application/views/templates_c和application/views/templates_c/cache_c文件夹。
然后以插件形式。在index.php中加载Smarty。
/*
* Date: 2009.8.16
* Author:DaGui
* Email:[email protected]
* QQ:308713166
*/
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
define('WEB_ROOT', 'http://192.168.12.190:81/vote/');
set_include_path('.' .PATH_SEPARATOR .'./library'.PATH_SEPARATOR.'./application/models/'.PATH_SEPARATOR . get_include_path());
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();//设置Zend Framework 自动载入类文件
$registry = Zend_Registry::getInstance();

//配置数据库参数,并连接数据库
$config=new Zend_Config_Ini('./application/config/config.ini',null, true);
Zend_Registry::set('config',$config);
$dbAdapter=Zend_Db::factory($config->general->db->adapter,$config->general->db->config->toArray());
$dbAdapter->query('SET NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter',$dbAdapter);

//对smarty模版进行初始化
include 'Smarty/Smarty.class.php';
$views = new Smarty();
$views->left_delimiter = "{{";
$views->right_delimiter = "}}";
$views->compile_dir = 'application/views/templates_c';
$views->cache_dir = 'application/views/templates_c/cache_c';
$views->template_dir = 'application/views/templates';
function smarty_block_dynamic($param,$content,&$views)
{
return $content;
}
$views->register_block('dynamic','smarty_block_dynamic',false);
Zend_Registry::set('views', $views);

//创建验证对象
$auth = Zend_Auth::getInstance();
//创建访问权限对象
$acl = new Common_Plugin_MyAcl();

//设置控制器
$frontController =Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('/vote')//设置基本路径
->setParam('noViewRenderer', true)
->registerPlugin(new Common_Plugin_MyAuth($auth, $acl))
->registerPlugin(new Zend_Controller_Plugin_ErrorHandler())
->setControllerDirectory('./application/controllers')
->throwExceptions(true)
->dispatch();
?>


之后在控制器层我的代码如下:
class IndexController extends Zend_Controller_Action
{
protected $views; /*模板对象*/
protected $data; /*传递模版变量的对象*/
function init()
小弟我用ZF框整合smarty,出了点异常,请各位帮忙看下了

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频