您的位置:首页 > 编程语言 > PHP开发

[转]最原始的Zend Framework整合Smarty简易方法

2011-04-19 22:13 337 查看

文章来源:

http://bbs.zfchina.org/viewthread.php?tid=4&extra=page%3D3

Zend Framework整合Smarty简易方法

Index.php

<?php
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set('Asia/Shanghai');
set_include_path('.' . PATH_SEPARATOR . './library'
. PATH_SEPARATOR . './application/models/'
. PATH_SEPARATOR . get_include_path());
include "./library/Zend/Loader.php";
include "./library/Smarty/Smarty.class.php";
$smarty = new Smarty();
$smarty -> template_dir = "templates";
$smarty -> compile_dir = "templates_c";
$smarty -> left_delimiter = "{{";
$smarty -> right_delimiter = "}}";
Zend_Loader::loadClass('Zend_Controller_Front');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');

$config = new Zend_Config_Ini('./application    /config.ini','general');
$registry = Zend_Registry::getInstance();
$registry -> set('config',$config);
$registry -> set('smarty',$smarty);
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
$frontController = Zend_Controller_Front::getInstance();
$frontController ->   setControllerDirectory('./application/controllers');
$frontController -> setParam('noViewRenderer', true);
$frontController -> throwExceptions(true);
$frontController -> dispatch();
?>


IndexController.php

<?php
class IndexController extends Zend_Controller_Action
{
public $view;
function init() {
$this->view = Zend_Registry::get('smarty');
$baseurl = $this->_request->getBaseUrl();
$this->view->assign('baseurl',$baseurl);
Zend_Loader::loadClass('Album');
}
function indexAction(){
$title = "My Albums";
$this->view->assign('title',$title);
$this->view->display('index.html');
}
function addAction() {

}
function editAction() {

}
function deleteAction() {

}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: