本文阐述了Smarty使用自定义资源的方式,
分享给你供你
参考。以下是如下:
< PHP
将这些
函数放到您的
应用程序中的某个地方。
功能db_get_template(tpl_name美元美元美元,tpl_source,smarty_obj)
{
在这里进行数据库调用以获取/您的模板,
填充 / / tpl_source美元
$ =新SQL;
为SQL ->
查询(选择tpl_source
从my_table
在tpl_name =tpl_name美元);
如果($ SQL -> num_rows){
tpl_source美元美元= SQL ->记录{ 'tpl_source};
返回true;
{人}
返回false;
}
}
功能db_get_timestamp(tpl_name美元美元美元,tpl_timestamp,smarty_obj)
{
做数据库调用来填充 / / tpl_timestamp美元。
$ =新SQL;
为SQL ->查询(选择tpl_timestamp
从my_table
在tpl_name =tpl_name美元);
如果($ SQL -> num_rows){
tpl_timestamp美元美元= SQL ->记录{ 'tpl_timestamp};
返回true;
{人}
返回false;
}
}
功能db_get_secure(tpl_name美元,美元smarty_obj)
{
所有模板
都是安全的/假定的
返回true;
}
功能db_get_trusted(tpl_name美元,美元smarty_obj)
{
用于模板
}
资源名db
Smarty美元-> register_resource(数据库
db_get_timestamp
db_get_secure
db_get_trusted ))
来自PHP
脚本的资源
Smarty美元->
显示(分贝:指标。物流);
>
希望本文有助于基于PHP程序设计的聪明人。