小弟我用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()
{
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.