关于section的倒序实现 step是步长,肯定不会影响你的排序的需要把你的数组倒序一下使用array_reverse就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是在你的php文件里$indexrows = array_reverse($indexrows); 只要给step属性指定为负数,就可以实现从后向前的循环。lz看看是不是其他地方出错了 只修改 section 中间的HTML内容的话,会影响输出结果,但是就是section的这几个属性设置了没有用 http://www.hbcms.com/main/smarty/language.function.section.html手册有解释 把数组reverse一下不很简单吗,为什么非要在模板里实现呢 如果你试不出来又想先要效果可以在模板插 php 反转 array 在PHP里试一下,不用在模板里修改。 {?$indexrows = array_reverse($indexrows);?} {?section name=i loop=$indexrows ?} {?if $indexrows[i].name1 != ""?} <li> <a href="{?$indexrows[i].c1?}">{?$indexrows[i].name1?} </a> </li> {?/if?} {?if $indexrows[i].name2 != ""?} <li> <a href="{?$indexrows[i].c2?}">{?$indexrows[i].name2?} </a> </li> {?/if?} {?/section?}不行{?$indexrows = array_reverse($indexrows);?}当作字符串输出了。使用{php}{?$indexrows = array_reverse($indexrows);?}{/php}{php} $indexrows = array_reverse($indexrows);{/php}也不行,都是把代码作为字符串输出了 用黑刀DeZender4.3解密出来的php源码不能跑,有变量未定义,请问有什么其他工具可以解密么 在模板里包含php即可处理$indexrows 要怎么写呢,我试过以上几种都不对,对SMARTY不太熟,谢谢 要怎么写呢,我试过以上几种都不对,对SMARTY不太熟,谢谢 <{section name=i loop=$indexrows start=6 step=-1}>start为你数组长度.比如说上面就是表示有6条记录.这需要匹配的. include_once("Smarty/Smarty.class.php"); //包含smarty类文件$smarty = new smarty(); //建立smarty实例对象$smarty$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量$smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存$smarty->template_dir = "templates/tpl"; //设置模板目录$smarty->compile_dir = "templates/compiles"; //设置编译目录$smarty->cache_dir = "templates/cache"; //缓存文件夹$smarty->left_delimiter = "<{";$smarty->right_delimiter = "}>";$smarty->debugging = false;$arrTest = array( array('name2'=>'111', 'name1'=>'1', 'c1'=>'11'), array('name2'=>'222', 'name1'=>'2', 'c1'=>'22'), array('name2'=>'333', 'name1'=>'3', 'c1'=>'33'), array('name2'=>'444', 'name1'=>'4', 'c1'=>'44'), array('name2'=>'555', 'name1'=>'5', 'c1'=>'55'), array('name2'=>'666', 'name1'=>'6', 'c1'=>'66'),);$smarty->assign('indexrows', $arrTest);$smarty->display("index.tpl");<{section name=i loop=$indexrows start=6 step=-1}> <p> <a href="<{$indexrows[i].c1}>"><{$indexrows[i].name1}> </a> </p> <{/section}>你的出不来是因为你哪块写错了,这没有什么好争论的,看我的测试程序! 我的模板文件是用index.html写的,且里面使用了{? code ?} 不知道是不是这个问题。现在就是想知道哪里错了。 谢谢您的回答。本人不会php,只是在修改源码的时候遇到这个问题。我并不是什么都没有试过就老是跑来问为什么,只是有些高手总会以为简单的对了,复杂的问题也一样处理就是了,但是实际问题往往不是一层内容,而是好几层内容叠加起来的问题。现在结帖。最后通过追踪程序运行文件发现,该模板不是程序最后使用的SMARTY模板,在程序运行期间会再生成一个SMARTY模板,而在该模板中将section转变成了foreach,因此无论如何添加都不起作用。{?section ... ?}语法一开始就觉得奇怪不像smarty语法<{section ...}>而是php语法,最后果然这里是有点问题的。不知道以上解释是否合理。 数组不重复输出 关于PEAR::DB_DataObject php 菜鸟问题 template('index')报错 类似于kaixin001图片上传的思路 请问PHP可以调用MATLAB的m文件吗 网站性能监控 什么网站比较好 郁闷了,请高手帮助(php sql语句的问题) 这个怎么办? Undefined variable: HTTP_SERVER_VARS php中的类型转换 想做个视频直播站,不知道如何入手 实现批量修改数据问题,UPDATE时想在原来该字段基础上连接新内容 高手来解释一句话
lz看看是不是其他地方出错了
只修改 section 中间的HTML内容的话,会影响输出结果,但是就是section的这几个属性设置了没有用
手册有解释
可以在模板插 php 反转 array
在PHP里试一下,不用在模板里修改。
{?$indexrows = array_reverse($indexrows);?}
{?section name=i loop=$indexrows ?}
{?if $indexrows[i].name1 != ""?}
<li> <a href="{?$indexrows[i].c1?}">{?$indexrows[i].name1?} </a> </li>
{?/if?}
{?if $indexrows[i].name2 != ""?}
<li> <a href="{?$indexrows[i].c2?}">{?$indexrows[i].name2?} </a> </li>
{?/if?}
{?/section?}不行
{?$indexrows = array_reverse($indexrows);?}当作字符串输出了。
使用{php}{?$indexrows = array_reverse($indexrows);?}{/php}
{php} $indexrows = array_reverse($indexrows);{/php}
也不行,都是把代码作为字符串输出了
用黑刀DeZender4.3解密出来的php源码不能跑,有变量未定义,请问有什么其他工具可以解密么
要怎么写呢,我试过以上几种都不对,对SMARTY不太熟,谢谢
要怎么写呢,我试过以上几种都不对,对SMARTY不太熟,谢谢
start为你数组长度.
比如说上面就是表示有6条记录.
这需要匹配的.
include_once("Smarty/Smarty.class.php"); //包含smarty类文件
$smarty = new smarty(); //建立smarty实例对象$smarty
$smarty->config_dir="Smarty/Config_File.class.php"; // 目录变量
$smarty->caching=false; //是否使用缓存,项目在调试期间,不建议启用缓存
$smarty->template_dir = "templates/tpl"; //设置模板目录
$smarty->compile_dir = "templates/compiles"; //设置编译目录
$smarty->cache_dir = "templates/cache"; //缓存文件夹
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
$smarty->debugging = false;$arrTest = array(
array('name2'=>'111', 'name1'=>'1', 'c1'=>'11'),
array('name2'=>'222', 'name1'=>'2', 'c1'=>'22'),
array('name2'=>'333', 'name1'=>'3', 'c1'=>'33'),
array('name2'=>'444', 'name1'=>'4', 'c1'=>'44'),
array('name2'=>'555', 'name1'=>'5', 'c1'=>'55'),
array('name2'=>'666', 'name1'=>'6', 'c1'=>'66'),
);
$smarty->assign('indexrows', $arrTest);
$smarty->display("index.tpl");
<{section name=i loop=$indexrows start=6 step=-1}>
<p> <a href="<{$indexrows[i].c1}>"><{$indexrows[i].name1}> </a> </p>
<{/section}>
你的出不来是因为你哪块写错了,这没有什么好争论的,看我的测试程序!
我的模板文件是用index.html写的,且里面使用了{? code ?} 不知道是不是这个问题。
现在就是想知道哪里错了。
谢谢您的回答。本人不会php,只是在修改源码的时候遇到这个问题。我并不是什么都没有试过就老是跑来问为什么,只是有些高手总会以为简单的对了,复杂的问题也一样处理就是了,但是实际问题往往不是一层内容,而是好几层内容叠加起来的问题。
现在结帖。
最后通过追踪程序运行文件发现,该模板不是程序最后使用的SMARTY模板,在程序运行期间会再生成一个SMARTY模板,而在该模板中将section转变成了foreach,因此无论如何添加都不起作用。
{?section ... ?}语法一开始就觉得奇怪不像smarty语法<{section ...}>而是php语法,最后果然这里是有点问题的。
不知道以上解释是否合理。