下面为smarty模板的配置文件,smarty配置的详细说明以及如何注册自己所需要的smarty函数 config.inc.php

<?php

/**

* Smarty 调用

* www.dafei.net

*/

/*** 新建 Smarty 对象 */

require_once (dirname(__FILE__).'/Smarty/libs/Smarty.class.php');

$smarty = new Smarty;

//$Smarty->caching = true; //决定是否缓存文件执行是生成的文件

//$Smarty->cache = true; //开启缓存

//$Smarty->cache_lifetime = 300; //缓存时间 单位秒

$smarty->compile_check = true; //每次执行时查看模板的内容是否改变

$smarty->debugging = false; //debugging 控制台 这是一个开关参数 如打开将显示 Smarty 变量和运行状态的调试窗口

/** 下面这几个目录可以根据自己的情况设置 **/

$smarty->template_dir = dirname(__FILE__).'/../templates'; //模板目录

$smarty->config_dir = dirname(__FILE__).'/../libs/config'; //默认的 config 文件目录名 默认为 ./configs

$smarty->compile_dir = dirname(__FILE__).'/../libs/templates_c'; //是 Smarty 默认的编译模板目录名 默认为 ./templates_c

$smarty->cache_dir = dirname(__FILE__).'/../libs/cache'; //默认的模板缓存目录名 默认为 ./cache

$smarty->left_delimiter = '<!--{'; //模板定界符 默认 {}

$smarty->right_delimiter = '}-->';

/******************************* 注册自己需要的smarty函数 ********************************/

//截取字符串 调用 { $str|smarty_gbstr:20:"..." }

function smarty_gbstr( $str, $length = -1, $s = "" )

{

$temp = strip_tags( $str );

if( ord( $temp[$length-1] ) > 128 ) {

for( $i = $j = 0; $i < strlen( $temp ) && $i < $length; $i++ ) {

if( $i == $length -1 && ord( $temp[$i] ) > 128 )

$length--;                //        如果最后一字节是中文,使截取长度减一以免截断

if( ord( $temp[$i] ) > 128 )

$i++;

}

}

if( strlen( $temp ) > $length ) {

return substr( $temp, 0, $length ).$s;

}

if( $length == -1 )

return $temp;

return substr( $temp, 0, $length );

}

$smarty->register_function("smarty_gbstr", "smarty_gbstr"); //注册函数

最新文章

  1. Android local.properties 文件读取
  2. 在xampp中配置dvwa
  3. 安装Java的IDE Eclipse时出现java.net.SocketException,出现错误Installer failed,show.log
  4. Visual Studio前端开发工具/扩展
  5. LoadRunner 脚本学习 -- 动态储存方式和静态储存方式
  6. 网页绘制图表 Google Charts with JavaScript #2 ....与ASP.NET网页结合 (ClientScriptManager.RegisterStartupScript 方法)
  7. 【转】Eclipse Java注释模板设置详解
  8. Google 开源项目风格指南阅读笔记(C++版)
  9. eclipse怎么恢复原状
  10. 性能测试工具 wrk 使用教程
  11. html + css3 demo
  12. layui(七)——rate组件常见用法总结
  13. Scala 继承
  14. nil Nil NULL NSNull 之间的区别
  15. 图的基本算法(BFS和DFS)
  16. Android Usb Camera HAL框架
  17. SQL学习笔记2
  18. git —— Feature分支
  19. 好用的eclipse properties插件
  20. 「Python」socket指南

热门文章

  1. 关于typedef的一些小知识
  2. 78.objects对象所属类原理分析
  3. 微信小程序自定义分享封面
  4. JAVA 创建文件和文件夹,删除文件和文件夹的实用工具
  5. SQL基础教程(第2版)第3章 聚合与排序:3-1 对表进行聚合查询
  6. Nginx和php交互的两种方式
  7. 28. docker swarm 容器编排简介
  8. Linux系统提示无法获得锁
  9. Python与mongo交互
  10. c#学习笔记01——引用&amp;类