View集成Smarty模板系统的方法(3)

<?php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { /** * Initialize Smarty view */ protected function _initSmarty() { $smarty = new Lq_View_Smarty (); $smarty->setScriptPath('/www/zf_demo1/application/views/scripts'); return $smarty; } }

/zf_demo1/application/controllers/IndexController.php

<?php class IndexController extends Zend_Controller_Action { public function init() { /* * Initialize action controller here */ } public function indexAction() { $this->_helper->getHelper('viewRenderer')->setNoRender(); $this->view = $this->getInvokeArg ( 'bootstrap' )->getResource ( 'smarty' ); $this->view->book = 'Hello World! '; $this->view->author = 'by smarty'; $this->view->render('index/index.tpl'); } }

/zf_demo1/application/views/scripts/index/index.tpl

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> {$book} {$author} </body> </html>

如果需要配置smarty可以打开/zf_demo1/library/smartylib/Smarty.class.php文件进行相应配置例如

/** * Initialize new Smarty object * */ public function __construct() { // selfpointer needed by some other class methods $this->smarty = $this; if (is_callable('mb_internal_encoding')) { mb_internal_encoding(Smarty::$_CHARSET); } $this->start_time = microtime(true); // set default dirs $this->setTemplateDir('/www/zf_demo1/temp/smarty' . DS . 'templates' . DS) ->setCompileDir('/www/zf_demo1/temp/smarty' . DS . 'templates_c' . DS) ->setPluginsDir(SMARTY_PLUGINS_DIR) ->setCacheDir('/www/zf_demo1/temp/smarty' . DS . 'cache' . DS) ->setConfigDir('/www/zf_demo1/temp/smarty' . DS . 'configs' . DS); $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl'; if (isset($_SERVER['SCRIPT_NAME'])) { $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); } }

更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b23b08f755490716057094058ded30cd.html