smarty 模板分页代码与调用方法
level e member's product commend list public function product_comm($size = 5){ $pre = $size <> 5 && !empty($_request['lb']) ? " and prolb like '%".$_request['lb']."%' " : ""; $this->where = " judge_flag = 0 and pubname = '".$_request['user']."' $pre "; $sql = " select id, pingpai, img, huohao from user_proinfo where ".$this->where. " order by pubtime desc "; $res = $this->selectrs->selectlimit($sql, $size, ($this->page - 1) * $size ); $this->navipage_cm("`user_proinfo`", $size, $this->where); return $res; } // embed in all must be used cat page function private function navipage_cm($table, $size, $where){ $count = $this->selectrs->getone("select count(*) from $table where $where "); $pages = @ceil($count/$size); for ($i = 0; $i <= $pages; $i++) $arr[] = $i; $navi_cm = array( "option" => $arr, "page" => $this->page, "pages" => $pages, "count" => $count, 字串7 "size" => $size, "param" => $this->param ); $this->tpl->assign("navi_cm", $navi_cm); }
smarty代码
<table width="100%" border="0" cellpadding="0" cellspacing="0" > <form name="jump" method="post" action=""> <tr> <td height="28" align="center" valign="bottom">当前页 <!--{$navi_cm.page}-->/<!--{$navi_cm.pages}--> <!--{if $navi_cm.pages gt 1 && $navi_cm.page ne 1}--> <a href="?<!--{$navi_cm.param}-->&page=1">[ 首页 ]</a> <!--{else}--> [ 首页 ] <!--{/if}--> <!--{if $navi_cm.pages gt 1 && $navi_cm.page ne 1}--> <a href="?<!--{$navi_cm.param}-->&page=<!--{$navi_cm.page-1}-->">[ 上一页 ]</a> <!--{else}--> [ 上一页 ] <!--{/if}--> <!--{if $navi_cm.pages gt 1 && $navi_cm.page ne $navi_cm.pages}--> <a href="?<!--{$navi_cm.param}-->&page=<!--{$navi_cm.page+1}-->">[ 下一页 ]</a> <!--{else}--> [ 下一页 ] <!--{/if}--> <!--{if $navi_cm.pages gt 1 && $navi_cm.page ne $navi_cm.pages}--> <a href="?<!--{$navi_cm.param}-->&page=<!--{$navi_cm.pages}-->">[ 末页 ]</a> <!--{else}--> [ 末页 ] <!--{/if}--> 转到 字串6 <select name="changepage" onchange="re_jump('<!--{$navi_cm.param}-->')"> <!--{html_options options=$navi_cm.option selected=$navi_cm.page}--> </select> </td> </tr> </form> </table>
关于smarty模板分析
基本语法
所有的smarty标签都被加上了定界符.在smarty里,所有定界符以外的内容都是静态的,当smarty遇到了模板标签,将尝试解释他们,然后再以恰当的方式输出.
默认情况下是 {和},但它们是可定制的.定制方法是:
$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';
1.注释
模板注释被*号包围,例如 {* this is a comment *}
smarty注释将不被输出.它是模板内在的注释.
2.变量
模板变量以$开头,可以包含数字,字母和下划线。
config_file变量是例外要用#变量名#的方法引用
3.函数
smarty标签输出一个变量或者调用某种函数.
在定界符内函数和其属性将被处理和输出.例如:
{funcname attr1="val" attr2="val"}.
funcname为函数的名称比如:include等,attr1,attr2为属性名,val为属性相应的值。
在模板里无论是内建函数还是自定义函数都有相同的语法.
内建函数将在smarty内部工作,例如 {if}, {section} 和{strip}.他们不能被修改.
本文链接:http://www.phprm.com/frame/36168.html
收藏随意^^请保留教程地址.