这几天,我在Smarty下写了一个plugin,感觉比较有用,大家有喜欢的,拿去用吧.
安装:
1: 安装Smarty(这个不用我说了吧?)
2: 将我的代码丢到/libs/plugins/下,以function.fetchcontent.php保存起来
使用:
直接在templates下的模板使用此定制函数.例如:在我这里<{fetchcontent id=3}>
注意:
数据库必须有ID这个字段
代码:
安装:
1: 安装Smarty(这个不用我说了吧?)
2: 将我的代码丢到/libs/plugins/下,以function.fetchcontent.php保存起来
使用:
直接在templates下的模板使用此定制函数.例如:在我这里<{fetchcontent id=3}>
注意:
数据库必须有ID这个字段
代码:
* Name: fetchcontent本人接手中小型网站,费用面谈.
* Purpose: fetch content from Database * @author Frank * @link http://smarty.php.net/manual/en/{counter} * (Smarty online manual) * @param array parameters * @param Smarty * @return string */ function smarty_function_fetchcontent($params,&$smarty) { require('./libs/adodb/adodb.inc.php'); require('./configs/config.inc.php'); $conn = &ADONewConnection('mysql'); $conn->debug=0; $conn->Connect($dbhost,$dbusername,$dbpassword,$dbname); $mytable = isset($params['mytable'])?$params['mytable']:'articles'; $myid = isset($params['id'])?$params['id']:'1'; $query = "SELECT * FROM ".$mytable." where id=".$myid; $rs = $conn->Execute($query); if(!$rs) { return false; }else{ return $rs->fields['content']; } } /* vim: set expandtab: */ ?>