Smarty使用自定义资源的方法
更新时间:2015年08月08日 16:15:22 作者:cooledit2730
这篇文章主要介绍了Smarty使用自定义资源的方法,实例分析了smarty自定义资源的定义与使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了Smarty使用自定义资源的方法。分享给大家供大家参考。具体如下:
<?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"); ?>
希望本文所述对大家基于smarty的php程序设计有所帮助。
相关文章
Yii2使用小技巧之通过 Composer 添加 FontAwesome 字体资源
前天帮同事改个十年前的网站 bug,页面上一堆 include require 不禁让人抱头痛哭。看到 V2EX 上的讨论说,写 PHP 不用框架等同于耍流氓。Yii Framework 是我使用了 2 年多的 PHP 框架,器大活好,皮实耐操。 Yii2 还在 Beta 中,不过不影响拿来预研。2014-06-06将博客园(cnblogs.com)数据导入到wordpress的代码
博客园限制太多,于是决定从博客园(cnblogs)更换自己个人的博客。WORDPRESS口碑还不错,于是决定用用看。之前发的数百篇日志需要导入过来,在网上搜了一会,发现没有这个插件,无奈只能自己写一个2013-01-01
最新评论