PHP有没有那种模板引擎,就是在模板里面能写SQL语句的。 本帖最后由 subendong 于 2011-01-10 13:10:56 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看codeigniter框架http://codeigniter.org.cn/user_guide/database/index.html dedecms的模板可以,其实你完全可以自己去实现个sql标签, 写这种烂代码都要*&*(&@(¥#8&%(@&#* 其实这个用框架或者原生的PHP应该都是可以实现的,你写好一个方法,进行调用就可以了 我擦,你用dreamwave拖动几下就成了。 //解析模板中的标签 $temp是模板中的字符串 解析后可以把返回值保存成模板缓存下次引用即可function temp_parse($temp) { $temp = preg_replace("/([\n\r]+)\t+/s","\\1",$temp); $temp = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}",$temp); $temp = preg_replace("/\{\/get\}/","<?php } unset(\$DATA); ?>",$temp); $temp = preg_replace("/\{get\s+([^}]+)\}/e", "temp_getparse('\\1')", $temp); $temp = preg_replace("/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$temp); $temp = preg_replace("/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$temp); $temp = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/","<?php echo \\1;?>",$temp); return $temp;}//解析 模板中SQL标签function temp_getparse($str){ preg_match_all("/([a-z]+)\=\"([^\"]+)\"/i", stripslashes($str), $matches, PREG_SET_ORDER); foreach($matches as $v) { $r[$v[1]] = $v[2]; } extract($r); if(!isset($sql)) $sql = ''; if(!isset($rows)) $rows = 0; if(!isset($return) || !preg_match("/^\w+$/i", $return)) $return = 'r'; $str = substr($str, -1) == '/' ? "<?php \${$return} = get(\"$sql\", -1);?>" : "<?php \$DATA = get(\"$sql\", $rows);foreach(\$DATA AS \$n => \${$return}) { \$n++;?>"; return $str;}//模板中 自定义查询SQL 其中$msql是一个SQL的类 自己写或者网上找找 很多function bbsget($sql,$rows = 0){ if(!$sql) return false; global $msql; $rows = intval($rows); $limit = $rows>1 ? " LIMIT $rows" : ''; $data = $rows<2 ? $msql->getone($sql) : $msql->select($sql.$limit); return $data;}上面是基本思路 和 详细代码了,我自己一个项目中用的,但不能直接使用,你需要整理一下。像你说这个例子,在模板中就这样写就行了<!--{get sql="select BlockName,ResourceMaterial,ResourceSpecification from View_Resource where ReMarketID=$M.ID" row='10'}--> <tr> <td>{$r[BlockName]}</td> <td>{$r[ResourceMaterial]}</td> </tr><!--{/get}-->这个算是比较基础的应用了,不过给你码代码真不容易,编辑器不好用,记得给分啊 自己写个标签。如ls某位兄弟说的 dede里面 很多都支持吧!smarty {php}{/php}phpcms 忘了,但绝对可以 高手帮忙看一下这个警告是什么意思(php)在线等 网页上直播实况视屏怎么做 每次调用db.php里面的方法都要实例化和链接 请解答!谢谢 求一款能调试PHP webservice的工具或者方法, 最好能够跟踪到server端的代码的! discuz x1.5开发嵌入点问题 【分享】PHP 读取XML自动过滤 CDATA samarty 引入问题? 开发商城系统,遇到的问题 请教一个apache Rewrite匹配规则 PHPExcel 导出csv格式文件,怎么才能使得记事本和excel打开正常 关于smarty 数组提取问题? 怎么用php来实现在线文件上传和下载?
//解析模板中的标签 $temp是模板中的字符串 解析后可以把返回值保存成模板缓存下次引用即可
function temp_parse($temp) {
$temp = preg_replace("/([\n\r]+)\t+/s","\\1",$temp);
$temp = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}",$temp);
$temp = preg_replace("/\{\/get\}/","<?php } unset(\$DATA); ?>",$temp);
$temp = preg_replace("/\{get\s+([^}]+)\}/e", "temp_getparse('\\1')", $temp);
$temp = preg_replace("/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$temp);
$temp = preg_replace("/\{\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff:]*\(([^{}]*)\))\}/","<?php echo \\1;?>",$temp);
$temp = preg_replace("/\{(\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/","<?php echo \\1;?>",$temp); return $temp;
}
//解析 模板中SQL标签
function temp_getparse($str)
{
preg_match_all("/([a-z]+)\=\"([^\"]+)\"/i", stripslashes($str), $matches, PREG_SET_ORDER);
foreach($matches as $v)
{
$r[$v[1]] = $v[2];
}
extract($r);
if(!isset($sql)) $sql = '';
if(!isset($rows)) $rows = 0;
if(!isset($return) || !preg_match("/^\w+$/i", $return)) $return = 'r';
$str = substr($str, -1) == '/' ? "<?php \${$return} = get(\"$sql\", -1);?>" : "<?php \$DATA = get(\"$sql\", $rows);foreach(\$DATA AS \$n => \${$return}) { \$n++;?>"; return $str;
}
//模板中 自定义查询SQL 其中$msql是一个SQL的类 自己写或者网上找找 很多
function bbsget($sql,$rows = 0)
{
if(!$sql) return false;
global $msql;
$rows = intval($rows);
$limit = $rows>1 ? " LIMIT $rows" : '';
$data = $rows<2 ? $msql->getone($sql) : $msql->select($sql.$limit);
return $data;
}
上面是基本思路 和 详细代码了,我自己一个项目中用的,但不能直接使用,你需要整理一下。
像你说这个例子,在模板中就这样写就行了<!--{get sql="select BlockName,ResourceMaterial,ResourceSpecification from View_Resource where ReMarketID=$M.ID" row='10'}--> <tr>
<td>{$r[BlockName]}</td>
<td>{$r[ResourceMaterial]}</td>
</tr>
<!--{/get}-->
这个算是比较基础的应用了,不过给你码代码真不容易,编辑器不好用,记得给分啊
phpcms 忘了,但绝对可以