小弟我用ZF框整合smarty,出了點異常,請各位幫忙看上了
來源:互聯網
上載者:User
我用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();
?>
之後在控制器層My Code如下:
class IndexController extends Zend_Controller_Action
{
protected $views; /*模板對象*/
protected $data; /*傳遞模版變數的對象*/
function init()
{
$this->registry = Zend_Registry::getInstance();
$this->views = Zend_Registry::get('views');
$this->data = $this->_request->getBaseUrl();
}
public function smartyAction()
{