Smarty使用自定義資源的方法
更新時間:2015年08月08日 16:15:22 作者:cooledit2730
這篇文章主要介紹了Smarty使用自定義資源的方法,實(shí)例分析了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");
?>
希望本文所述對大家基于smarty的php程序設(shè)計有所幫助。
相關(guān)文章
thinkphp ajaxfileupload實(shí)現(xiàn)異步上傳圖片的示例
本篇文章主要介紹了thinkphp ajaxfileupload實(shí)現(xiàn)異步上傳圖片的示例,具有一定的參考價值,有興趣的可以了解一下2017-08-08
基于ThinkPHP5.0實(shí)現(xiàn)圖片上傳插件
thinkphp5.0 圖片上傳插件可預(yù)覽裁剪圖片和保存原圖片,執(zhí)行裁剪圖片后會刪除 裁剪的原圖片目錄,以便減少空間。具體實(shí)現(xiàn)代碼大家參考下本文2017-09-09
適用于抽獎程序、隨機(jī)廣告的PHP概率算法實(shí)例
做網(wǎng)站類的有時會弄個活動什么的,來讓用戶參加,既吸引用戶注冊,又提高網(wǎng)站的用戶活躍度。同時參加的用戶會獲得一定的獎品,有100%中獎的,也有按一定概率中獎的,大的比如中個ipad、iphone5,小的中個Q幣什么的2014-04-04
laravel框架使用FormRequest進(jìn)行表單驗證,驗證異常返回JSON操作示例
這篇文章主要介紹了laravel框架使用FormRequest進(jìn)行表單驗證,驗證異常返回JSON操作,涉及l(fā)aravel表單請求類的創(chuàng)建、使用及異常處理相關(guān)操作技巧,需要的朋友可以參考下2020-02-02
PHP結(jié)合Mysql數(shù)據(jù)庫實(shí)現(xiàn)留言板功能
這篇文章主要介紹了PHP結(jié)合Mysql數(shù)據(jù)庫實(shí)現(xiàn)留言板功能的相關(guān)資料,需要的朋友可以參考下2016-03-03
Laravel Eloquent ORM 實(shí)現(xiàn)查詢表中指定的字段
今天小編就為大家分享一篇Laravel Eloquent ORM 實(shí)現(xiàn)查詢表中指定的字段,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

