Smarty使用自定義資源的方法
本文實(shí)例講述了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"); ?>
希望本文所述對(duì)大家基于smarty的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
thinkPHP5(TP5)實(shí)現(xiàn)改寫跳轉(zhuǎn)提示頁面的方法
這篇文章主要介紹了thinkPHP5(TP5)實(shí)現(xiàn)改寫跳轉(zhuǎn)提示頁面的方法,結(jié)合實(shí)例形式分析了thinkPHP5跳轉(zhuǎn)提示頁面的修改步驟與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2017-10-10Yii凈化器CHtmlPurifier用法示例(過濾不良代碼)
這篇文章主要介紹了Yii凈化器CHtmlPurifier用法,可實(shí)現(xiàn)過濾不良代碼的功能,涉及在控制器、模型、過濾器及視圖中的相關(guān)使用技巧,需要的朋友可以參考下2016-07-07thinkPHP5.0框架自動(dòng)加載機(jī)制分析
這篇文章主要介紹了thinkPHP5.0框架自動(dòng)加載機(jī)制,較為詳細(xì)的分析了thinkPHP5.0自動(dòng)加載的概念、原理、用法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-03-03簡(jiǎn)單的php+mysql聊天室實(shí)現(xiàn)方法(附源碼)
這篇文章主要介紹了簡(jiǎn)單的php+mysql聊天室實(shí)現(xiàn)方法,詳細(xì)介紹了數(shù)據(jù)庫,框架頁面,登錄及信息的發(fā)布、展示功能實(shí)現(xiàn)技巧,并附帶了完整源碼供讀者下載參考,需要的朋友可以參考下2016-01-01基于Linux調(diào)試工具strace與gdb的常用命令總結(jié)
本篇文章是對(duì)Linux調(diào)試工具strace與gdb的常用命令進(jìn)行了總結(jié)與分析,需要的朋友參考下2013-06-06ecshop適應(yīng)在PHP7的修改方法解決報(bào)錯(cuò)的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猠cshop適應(yīng)在PHP7的修改方法解決報(bào)錯(cuò)的實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11