<?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() { } }
原文出处:Netkiller 系列 手札本文作者:陈景峯转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。