时间:2021-07-01 10:21:17 帮助过:4人阅读
{foreach $items as $item} {strip}。。。。。。。。。。。。。。。。。。。。。。。。。。。。{if $item->kind == "folder"} id}">{$item->name}
{elseif $item->type != "link"} id}">{$item->name}
{else} {$link_content=""} {$this_id=$item->id} {$search_link_query="select * from archive.file where id='$this_id'"} {$con = mysqli_connect("localhost","root","root")} {$result = mysqli_query($con,$search_link_query)} {mysqli_close($con)} {$row=mysqli_fetch_row($result)} {$link_content=$row[8]} {$item->name}
{/if}................................................... {/strip} {/foreach}
这个可以写在PHP里面,然后用用标签替换掉啊,在模板里面写什么连接数据库呢?
还是改你php吧 吧要添加的内容循环添加进去 页面直接调用就行了
感谢关注啊,我第一次用smarty,还是在别人代码基础上增加新功能。
不知道楼上所说的用标签替换掉,怎么替换掉?我也考虑过采用如下方式传送变量:
$smarty->assign("action", $action);
$smarty->display("folders.tpl");
在我看来,上面的方面只能是一次性的传送。但在我的表格中每条记录是不停的循环并且显示的,如果我要把前端每次循环的关键变量id传送到后端进行处理,那又应该如何做呢?
那问题就归结为: smarty模板中前端采用一个循环来显示内容,那我如何把每次循环中的关键变量传到后端,经过处理后又把结果返回该循环中呢?
其实,想想逻辑上也不难,大神们,有代码例子么?这里叩谢了。
吧你的后台代码贴出来 标识好 我看看
其实,我就非常纳闷了,咋就出现这么多“1”呢?
与该smarty相对应的后端php 代码为:(我已经尽量加注释了)
allowedRegion)); $files = do_action("files","search", array($search, $currentUser->allowedRegion)); $smarty->assign("folder", NULL); $paths = array("Search Result"); $path = new stdClass(); $path->id = NULL; $path->name = "Search Result"; $smarty->assign("paths", array($path));}else //对这个页面的另一动作是正常显示{ $folders = list_items("folders", $id); $folder = get_item("folders", $id); $files = list_items("files", $id); $smarty->assign("folder",$folder); $paths = $folder->path; if ($currentUser->level == 2) { unset($paths[0]); $paths = array_values($paths); } $smarty->assign("paths", $paths);}$items = array_merge($folders,$files); //获取到显示记录,并把多个记录组合起来$items = sort_items($items); //排序功能$smarty->assign("items", $items);$smarty->assign("action", $action);$smarty->display("folders.tpl");?> {if count($items) > 0} {foreach $items as $item} {strip} {if $item->kind == "folder"} 
{else} {if $item->type == "docx" || $item->type == "doc"} 
{else if $item->type == "xlsx" || $item->type == "xls"} 
{elseif $item->type == "pdf"} 
{elseif $item->type == "png" || $item->type == "gif" || $item->type == "jpg"} 
{elseif $item->type == "ppt" || $item->type == "pptx"} 
{elseif $item->type == "mp4"} 
{elseif $item->type == "link"} 
{else} 
{/if} {/if} {if $item->kind == "folder"} id}">{$item->name}
{elseif $item->type != "link"} id}">{$item->name}
{else} {$link_content=""} {$this_id=$item->id} {$search_link_query="select * from archive.file where id='$this_id'"} {$con = mysqli_connect("localhost","root","goldmine")} {$result = mysqli_query($con,$search_link_query)} {mysqli_close($con)} {$row=mysqli_fetch_row($result)} {$link_content=$row[8]} {$item->name}
{/if} {$item->createdByName}
{$item->created}
{$item->lastUpdated}
Visible
{if $item->size > 1000} {round(($item->size / 1024), 1)}MB {else} {$item->size}KB
{/if} {if $item->kind == "folder"} id}/Move')">
{elseif $item->kind == "file"} id}/Move')">
{/if} {if $item->kind == "folder"} id}">
{elseif $item->kind == "file"} id}">
{/if} id}" {if $item->kind == "folder"} {if $item->folderCount > 0 || $item->fileCount > 0} onclick="JavaScript:return confirm('This folder is not empty. If you delete it all content will also be deleted. Do you still want to continue?');">
{else} onclick="JavaScript:return confirm('Do you really want to delete this folder?');">
{/if} {elseif $item->kind == "file"} id}" onclick="JavaScript:return confirm('Do you really want to delete this file?');">
{/if} {/strip} {/foreach} {else} {if $action != "search"}
{/if} {if $action == "search"}
No files or folders could be found!
{else} This folder is empty!
{/if} 其实如果不管代码的话,我的问题归结下来就两个细节:
1. 在smarty模板中,怎么{$con = mysqli_connect("localhost","root","root")}就会产生这么多的“1”呢?表明连接数据库成功么?有无方法隐藏这个显示?
2.smarty模板中前端的循环,如果与后端php代码处理动态的进行数值传输呢?
我需要把每次循环中的关键变量传到后端,经过处理后又把结果返回该循环中呢,并且在该次循环中显示php传送过来的值。如果做到呢?
大神们,你们有办法解决么?希望给出代码示例,否则小弟不会做啊。谢谢啊。
奶奶的,我的语文是体育老师教的。
更正啊:在php代码部分,第一条注释为:
//该页面的基本功能就是在表格中显示某个区域里的文件或者文件夹,除文件和文件夹类型外我要增加一个类型:链接link,并且还增加其他一些与link链接这种类型相关的功能
模板中不要写逻辑代码,尽量都写到php中去。
2.smarty模板中前端的循环,如果与后端php代码处理动态的进行数值传输呢?
我需要把每次循环中的关键变量传到后端,经过处理后又把结果返回该循环中呢,并且在该次循环中显示php传送过来的值。如果做到呢? 交互不外乎两种,form提交到后端,或者ajax传值。
更正:
多次测试后,发现是{mysqli_close($con)}这句话产生了“1”,其结果为
如过是{mysqli_close($con)}这句话产生了“1”
那就把 {mysqli_close($con)} 删掉
xu版主来了,欢迎啊。
我就是这么干的,确实没有“1”了。但这么干,不会产生什么坏影响吧?比如,与数据库的链接占用内存?对系统还产生其他影响?
但细想想,应该没有多大事情,因为系统都采用$con这个表示链接,最多也就一个变量占用内存而得不到释放?
徐版主,这样删掉没有大问题吧?
如过是{mysqli_close($con)}这句话产生了“1”
那就把 {mysqli_close($con)} 删掉
这是没有问题的
那好,徐版主说没有问题了,那大概八九不离十了。
结贴。
这是没有问题的
人气教程排行
-
174次
1
php如何获取跳转前的url
-
174次
2
php格林威治时间转换成当前时间的方法
-
174次
3
为什么php不能做大型系统?
-
174次
4
range函数怎么用
-
174次
5
php中计算页面加载时间几种方法总结_PHP教程
-
174次
6
求帮助,关于paypal支付返回值修改订单状态
-
174次
7
typecho怎么配置文章内容页?
-
174次
8
PhpStorm左侧structure不显示文件的方法列表是这么回事?
-
174次
9
查看PHP的环境变量_PHP
-
174次
10
PHP Primary script unknown 解决方法总结
-
174次
11
php的命名空间与自动加载实现方法
-
174次
12
解决laravel 出现ajax请求419(unknown status)的问题
-
173次
13
php 如何删除mysql记录
-
173次
14
PHP如何替换数组中的指定元素
-
173次
15
怎么去除字符串中非汉字、非字母、非数字的字符
-
173次
16
mysql如何一次执行多条SQL语句
-
173次
17
修改header里面的Connection为close解决方法
-
173次
18
PHP基于session.upload_progress 实现文件上传进度显示功能详解
-
173次
19
php5.6.x到php7.0.x特性小结
-
172次
20
php为什么会出现504错误