<?php
//打開錯誤提示
error_reporting(E_ALL|E_STRICT);
//設定時區
date_default_timezone_set("Asia/Shanghai");
//指明引用檔案的路徑
set_include_path('.'.PATH_SEPARATOR.'./library'.PATH_SEPARATOR.'./app/model/'.PATH_SEPARATOR.get_include_path());
//必須手動加載Loader.php
include "Zend/Loader.php";
//自動加載類,使用時,直接實例化使用
function __autoload($class){
Zend_Loader::loadClass($class);
}
//getInstance()方法用來獲取前端控製器實例
$frontController = Zend_Controller_Front::getInstance();
//設定前端路由器的工作目錄,即cotroller
$frontController->setControllerDirectory(array("default"=>"app/controller"));
//拋出異常
$frontController->throwExceptions(true);
//設置基地址,方便以後url的跳轉用戶,注意,區分大小寫!
$frontController->setBaseUrl("/phpzend");
//使用smarty模版需關閉本身的視圖助手.
$frontController->setParam("noViewRenderer", true);
// 關閉錯誤提示,發生請求錯誤時候,轉到ErrorController的errorAction控製器
//$frontController->throwExceptions(false);
//對。。進行註冊
Zend_Registry::set("font", $frontController);
//------------配置Smarty模版 ----------------
include "smarty/Smarty.class.php";
/**
* 對smarty模版進行初始化
**/
$views = new Smarty();
//$views->left_delimiter = "{{";
//$views->right_delimiter = "}}";
$views->compile_dir = "app/template_c";
$views->cache_dir = "app/template_c/cache_c";
$views->template_dir = "app/template";
function smarty_block_dynamic($param,$content,&$views)
{
return $content;
}
$views->register_block("dynamic","smarty_block_dynamic",false);
Zend_Registry::set("views", $views);
//開始運行程序
$frontController->dispatch();
<?php
//控製器層
class IndexController extends Zend_Controller_Action{
var $views; /*模板對象*/
var $data; /*傳遞模版變數的對象*/
function init()
{
//拿回註冊過的對象
$this->views = Zend_Registry::get("views");
}
function indexAction()
{
//定義模版顯示的變數
$data['title']="hello world";
//傳遞變數到模版
$this->views->assign($data);
//顯示模版
$this->views->display("index/index.tpl");
echo "<p>in IndexController::indexAction()</p>";
}
function addAction()
{
}
}