php yaf smarty,Yaf 结合用户自定义的视图(模板)引擎Smarty(Yaf + Smarty)

Yaf 结合用户自定义的视图(模板)引擎Smarty(Yaf + Smarty)

来源:互联网

作者:佚名

时间:2015-08-06 07:55

对完成某个任务进行计时可使用progress_timer类,这个类对象在退出作用范围后,会输出对象创建后过去的时间,可申请多个类对象,这样可对多个任务进行统计。#inc

Yaf 结合用户自定义的视图(模板)引擎Smarty(Yaf + Smarty)

分类:

php开发

yafsmarty

(1)入口文件:/public/index.php:

define("DS", '/');

define('APPLICATION_PATH', dirname(__FILE__).DS.'..'.DS);//指向public上一级的目录 ../

$application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini");

$application->bootstrap()->run();

?>

(2)在引导程序

class Bootstrap extends Yaf_Bootstrap_Abstract{

public function _initConfig() {

//把配置保存起来

$arrConfig = Yaf_Application::app()->getConfig();

Yaf_Registry::set('config', $arrConfig);

}

//其他定义忽略......

public function _initSmarty(Yaf_Dispatcher $dispatcher) {

//init smarty view engine

$smarty = new Smarty_Adapter(null, Yaf_Registry::get("config")->get("smarty"));

$dispatcher->setView($smarty);

}

}

(3)添加类,使Smarty_Adapter

首先下载

vim Adapter.php

/*确保Smarty.class.php在Smarty/libs/下*/

Yaf_Loader::import( "Smarty/libs/Smarty.class.php"); /*基类目录为library*/

class Smarty_Adapter implements Yaf_View_Interface /*Smarty_Adapter类为yaf与smarty之间的适配器*/

{

/**

* Smarty object

* @var Smarty

*/

public $_smarty;

/**

* Constructor

*

* @param string $tmplPath

* @param array $extraParams

* @return void

*/

public function __construct($tmplPath = null, $extraParams = array()) {

$this->_smarty = new Smarty;

if (null !== $tmplPath) {

$this->setScriptPath($tmplPath);

}

foreach ($extraParams as $key => $value) {

$this->_smarty->$key = $value;

}

}

/**

* Return the template engine object

*

* @return Smarty

*/

public function getEngine() {

return $this->_smarty;

}

/**

* Set the path to the templates

*

* @param string $path The directory to set as the path.

* @return void

*/

public function setScriptPath($path)

{

if (is_readable($path)) {

$this->_smarty->template_dir = $path;

return;

}

throw new Exception('Invalid path provided');

}

/**

* Retrieve the current template directory

*

* @return string

*/

public function getScriptPath()

{

return $this->_smarty->template_dir;

}

/**

* Alias for setScriptPath

*

* @param string $path

* @param string $prefix Unused

* @return void

*/

public function setBasePath($path, $prefix = 'Zend_View')

{

return $this->setScriptPath($path);

}

/**

* Alias for setScriptPath

*

* @param string $path

* @param string $prefix Unused

* @return void

*/

public function addBasePath($path, $prefix = 'Zend_View')

{

return $this->setScriptPath($path);

}

/**

* Assign a variable to the template

*

* @param string $key The variable name.

* @param mixed $val The variable value.

* @return void

*/

public function __set($key, $val)

{

$this->_smarty->assign($key, $val);

}

/**

* Allows testing with empty() and isset() to work

*

* @param string $key

* @return boolean

*/

public function __isset($key)

{

return (null !== $this->_smarty->get_template_vars($key));

}

/**

* Allows unset() on object properties to work

*

* @param string $key

* @return void

*/

public function __unset($key)

{

$this->_smarty->clear_assign($key);

}

/**

* Assign variables to the template

*

* Allows setting a specific key to the specified value, OR passing

* an array of key => value pairs to set en masse.

*

* @see __set()

* @param string|array $spec The assignment strategy to use (key or

* array of key => value pairs)

* @param mixed $value (Optional) If assigning a named variable,

* use this as the value.

* @return void

*/

public function assign($spec, $value = null) {

if (is_array($spec)) {

$this->_smarty->assign($spec);

return;

}

$this->_smarty->assign($spec, $value);

}

/**

* Clear all assigned variables

*

* Clears all variables assigned to Zend_View either via

* {@link assign()} or property overloading

* ({@link __get()}/{@link __set()}).

*

* @return void

*/

public function clearVars() {

$this->_smarty->clear_all_assign();

}

/**

* Processes a template and returns the output.

*

* @param string $name The template to process.

* @return string The output.

*/

public function render($name, $value = NULL) {

return $this->_smarty->fetch($name);

}

public function display($name, $value = NULL) {

echo $this->_smarty->fetch($name);

}

}

?>

(4)修改

vim application.ini

[common]

application.directory = APPLICATION_PATH "/application"

application.dispatcher.catchException = TRUE

application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"

application.library = APPLICATION_PATH "/application/library"

application.baseUri = ''

;application.dispatcher.defaultModule = index

application.dispatcher.defaultController = index

application.dispatcher.defaultAction = index

;errors (see Bootstrap::initErrors)

application.showErrors=0

[smarty : common]

application.view.ext="tpl" ;;设置视图文件的后缀为 tpl

;smarty.left_delimiter = "{{" ;设置模板提取值时候的"{"情况

;smarty.right_delimiter = "}}" ;

smarty.template_dir

= APPLICATION_PATH "/application/views/"

smarty.compile_dir

= APPLICATION_PATH "/application/views/templates_c/"

smarty.cache_dir

= APPLICATION_PATH "/application/views/templates_d/"

;smarty.caching = 0;

;smarty.cache_lifetime = 600;

[product : smarty]

(5)基于Yaf + Smarty

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/308393.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

7-34 任务调度的合理性 (25 分)(思路加详解+兄弟们冲呀)

一:题目 假定一个工程项目由一组子任务构成,子任务之间有的可以并行执行,有的必须在完成了其它一些子任务后才能执行。“任务调度”包括一组子任务、以及每个子任务可以执行所依赖的子任务集。 比如完成一个专业的所有课程学习和毕业设计可…

.NET和.NET Core Web APi FormData多文件上传

【导读】最近因维护.NET和.NET Core项目用到文件上传功能,虽说也做过,但是没做过什么对比,借此将二者利用Ajax通过FormData上传文件做一个总结,通过视图提交表单太简单,这里不做阐述,希望对有需要的童鞋能有…

php 百度云 上传,求个PHP版百度云BOS上传文件的dome

[HTML] 纯文本查看 复制代码bce-bos-uploader simple demo开始上传var uploader new baidubce.bos.Uploader({browse_button: #file,bos_bucket: ,bos_endpoint: ,bos_ak: ,bos_sk: ,max_file_size: 1Gb,init: {FileUploaded: function (_, file, info) {var bucket info.bod…

在ubuntu上实现基于webrtc的多人在线视频聊天服务

最近研究webrtc视频直播技术,网上找了些教程最终都不太能顺利跑起来的,可能是文章写的比较老,使用的一些开源组件已经更新了,有些配置已经不太一样了,所以按照以前的步骤会有问题。折腾了一阵终于跑起来了,…

java并发练习之快乐影院

一:引言 这里是加了个同步块,来保证数据的准确性,用了个容器使,我们可以选位置 二:上码(这里是模拟在电影院选位置) package com.wyj.three;import java.util.ArrayList; import java.util.L…

用php编写一个日志系统,php利用单例模式实现日志处理类库

对于现在的应用程序来说,日志的重要性是不言而喻的。很难想象没有任何日志记录功能的应用程序运行在生产环境中。日志所能提供的功能是多种多样的,包括记录程序运行时产生的错误信息、状态信息、调试信息和执行时间信息等。在生产环境中,日志…

Azure DevOps+Docker+Asp.NET Core 实现CI/CD(二.创建CI持续集成管道)

前言本文主要是讲解如何使用Azure DevOpsDocker 来实现持续集成Asp.NET Core项目(当然 也可以是任意项目).上一篇:Azure DevOpsDockerAsp.NET Core 实现CI/CD(一 .简介与创建自己的代理池)觉得有帮助的朋友~可以左上角点个关注,右下角点个推荐今天我们废话不多说 直接开始正文 …

7-35 城市间紧急救援 (25 分)(思路加详解)

一:题目 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图。在地图上显示有多个分散的城市和一些连接城市的快速道路。每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上。当其他城市有紧急求助电话给你的时候&#xff0…

程序员修神之路--那些分布式事务解决方案

亲爱的,关注我吧为了保证分布式环境下数据强一致性,需要引入分布式事务,而分布式事务由于网络环境的不确定性,天生就很难实现。具体可以见上一篇。[分布式下,我想要强一致性]为了保证分布式事务的正确性,目前互联网领域…

7-36 社交网络图中结点的“重要性”计算 (30 分)(思路加详解)兄弟们PTA乙级题目冲起来

一:题目 在社交网络中,个人或单位(结点)之间通过某些关系(边)联系起来。他们受到这些关系的影响,这种影响可以理解为网络中相互连接的结点之间蔓延的一种相互作用,可以增强也可以减…

php防止cc攻击代码,防cc攻击PHP防CC攻击实现代码

这种时候您的统计系统(可能是量子、百度等)当然也是统计不到的。不过我们可以借助于一些防攻击的软件来实现,不过效果有时并不明显。下面我提供一段PHP的代码,可以起到一定的防CC效果。主要功能:在3秒内连续刷新页面5次以上将指向本机 http:/…

分享几个亲测有效的高效工作技巧

这里是Z哥的个人公众号每周五11:45 按时送达当然了,也会时不时加个餐~我的第「154」篇原创敬上大家好,我是Z哥。在工作中,你会发现有的小伙伴每天看上去很忙,但是好像产出的成果比旁边看上去工作轻松甚至有…

js变量和java变量相等,js中变量和jsp中java代码中变量互相访问解决方案

1。js变量获取jsp页面中java代码的变量值。方法:var JS变量名 我们常常会将js文件和jsp文件分开写,在js文件中,上面的方法似乎不管用了。也可以通过变通的方法来解决:a.jspaa.jsvar n document.getElementById(a).value; 使用jq…

7-37 模拟EXCEL排序 (25 分)(思路+详解+超时解决 兄弟们冲呀呀呀呀呀呀)

一:题目 Excel可以对一组纪录按任意指定列排序。现请编写程序实现类似功能。 输入格式: 输入的第一行包含两个正整数N(≤10 5 ) 和C,其中N是纪录的条数,C是指定排序的列号。之后有 N行,每行包含一条学生纪录。每条学生纪录由学号…

Azure DevOps+Docker+Asp.NET Core 实现CI/CD(三.实现CD持续部署管道)

前言本文主要是讲解如何使用Azure DevOpsDocker 来实现持续集成Asp.NET Core项目(当然 也可以是任意项目).上一篇:Azure DevOpsDockerAsp.NET Core 实现CI/CD(一 .简介与创建自己的代理池)Azure DevOpsDockerAsp.NET Core 实现CI/CD(二.创建CI持续集成管道)觉得有帮助的朋友~可…

7-1 寻找大富翁 (25 分)(思路加详解+两种做法(一种优先队列,一种vector容器))

一:题目 胡润研究院的调查显示,截至2017年底,中国个人资产超过1亿元的高净值人群达15万人。假设给出N个人的个人资产值,请快速找出资产排前M位的大富翁。 输入格式: 输入首先给出两个正整数N(≤10 6 )和M…

php项目通过不了压力测试,压力测试 – Apache ab测试和失败 – Apache或PHP配置问题?...

我写了一个RESTful Web服务,成为使用PHP和Restler库的移动应用程序的支柱.它运行在运行Windows Server 2008 R2,PHP 5.3.5,Apache 2.2.17和MySQL 5.5.8的开发服务器上.只是为了咯咯笑,我决定对我的开发服务器进行基准测试并遇到可能的配置问题如果我通过Windows CLI运行ab -k -…

matlab调用时间序列工具箱,matlab时间序列工具箱

【实例简介】matlab时间序列工具箱,【实例截图】【核心代码】824a746f-8093-4767-8426-cf0f7ceda7a6├── matrixcomp│ ├── adsmax.m│ ├── augment.m│ ├── cholp.m│ ├── chop.m│ ├── cod.m│ ├── Contents.m│ ├── cpltax…

7-39 魔法优惠券 (25 分)(思路加解释 用容器做的)加油兄弟们

一:题目 在火星上有个魔法商店,提供魔法优惠券。每个优惠劵上印有一个整数面值K,表示若你在购买某商品时使用这张优惠劵,可以得到K倍该商品价值的回报!该商店还免费赠送一些有价值的商品,但是如果你在领取…

.NET Core Web APi大文件分片上传研究

【导读】前两天发表利用FormData进行文件上传.NET和.NET Core Web APi FormData多文件上传,然后有人问要是大文件几个G上传怎么搞,常见的不就是分片再搞下断点续传,动动手差不多也能搞出来,只不过要深入的话,考虑的东西…