首页 后端开发 php教程 Smarty使用自定义资源的方法_PHP

Smarty使用自定义资源的方法_PHP

May 30, 2016 am 08:47 AM
smarty 自定义 资源

本文实例讲述了Smarty使用自定义资源的方法。分享给大家供大家参考。具体如下:

<&#63;php
// put these function somewhere in your application
function db_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
 // do database call here to fetch your template,
 // populating $tpl_source
 $sql = new SQL;
 $sql->query("select tpl_source
   from my_table
   where tpl_name='$tpl_name'");
 if ($sql->num_rows) {
 $tpl_source = $sql->record['tpl_source'];
 return true;
 } else {
 return false;
 }
}
function db_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj)
{
 // do database call here to populate $tpl_timestamp.
 $sql = new SQL;
 $sql->query("select tpl_timestamp
   from my_table
   where tpl_name='$tpl_name'");
 if ($sql->num_rows) {
 $tpl_timestamp = $sql->record['tpl_timestamp'];
 return true;
 } else {
 return false;
 }
}
function db_get_secure($tpl_name, &$smarty_obj)
{
 // assume all templates are secure
 return true;
}
function db_get_trusted($tpl_name, &$smarty_obj)
{
 // not used for templates
}
// register the resource name "db"
$smarty->register_resource("db", array("db_get_template",
     "db_get_timestamp",
     "db_get_secure",
     "db_get_trusted"));
// using resource from php script
$smarty->display("db:index.tpl");
&#63;>
登录后复制

希望本文所述对大家基于smarty的php程序设计有所帮助。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

如何在Netflix中快速设置自定义头像 如何在Netflix中快速设置自定义头像 Feb 19, 2024 pm 06:33 PM

如何在Netflix中快速设置自定义头像

Win11如何自定义背景图片 Win11如何自定义背景图片 Jun 30, 2023 pm 08:45 PM

Win11如何自定义背景图片

如何在Python中创建和自定义Venn图? 如何在Python中创建和自定义Venn图? Sep 14, 2023 pm 02:37 PM

如何在Python中创建和自定义Venn图?

如何在CakePHP中创建自定义分页? 如何在CakePHP中创建自定义分页? Jun 04, 2023 am 08:32 AM

如何在CakePHP中创建自定义分页?

Vue3中的render函数:自定义渲染函数 Vue3中的render函数:自定义渲染函数 Jun 18, 2023 pm 06:43 PM

Vue3中的render函数:自定义渲染函数

如何在装有 iOS 17 的 iPhone 上的 Apple Music 中启用和自定义交叉淡入淡出 如何在装有 iOS 17 的 iPhone 上的 Apple Music 中启用和自定义交叉淡入淡出 Jun 28, 2023 pm 12:14 PM

如何在装有 iOS 17 的 iPhone 上的 Apple Music 中启用和自定义交叉淡入淡出

如何在CodeIgniter中实现自定义中间件 如何在CodeIgniter中实现自定义中间件 Jul 29, 2023 am 10:53 AM

如何在CodeIgniter中实现自定义中间件

Eclipse中自定义快捷键设置的方法 Eclipse中自定义快捷键设置的方法 Jan 28, 2024 am 10:01 AM

Eclipse中自定义快捷键设置的方法

See all articles