|
主題: 寻求帮助用smarty写了一个批量删除的模板却不知道怎么传递参数 作者: hainuo 於 二月 03, 2008, 07:59:34 下午 程式碼: <div class="main"> <div class="mainmod"> <div class="column" id="c1" style="float:left;position:relative;width:25%;"> 前台侧栏 </div> <div class="column" id="c2" style="float:left;position:relative;width:75%;"> {* 中间要展现内容 *} <div class="mod modposition"> <div class="modcontent"> {* 提示信息 *} {include file="actionmessage.template"} <form name="listtest" id="listtest" action="/home.php" method="post"> <div class="field" > <table border = 1 > <tr> <th style=20%>选择</th> <th style=20% >标题</th> <th style=20%>游客</th> <th style=40%>ip</th> </tr> {foreach from=$allTest item=test} <tr> <td > <input type="checkbox" class="checkbox" name="id[]" value="{$test->getId()}" /> </td> <td > {$test->getTitle()} </td> <td > {$test->getAuthor()} </td> <td > {$test->getClientip()} </td> </tr> {/foreach} <tr> <td > <input class="checkbox" type="checkbox" name="all" id="all" value="1" onclick="CheckAll('listtest');" /> </td> <td > 全选 </td> <td >反选 </td> <td >清楚 </td> </tr> </table> </div> <div id="fields"> 确定 <input class="botton" type="submit" name="dellisttest" value="删除" />所选留言 <input name="op" value="dellisttest" type="hidden" /> </div> </form> 我用这个 传递变量id[]不知道怎么传递。用checkbox取得id值然后将取得的id打包成数组传递出去 请问如何将id打包成数组啊。然后在action类中如何取得这个数组啊。 主題: Re: 寻求帮助用smarty写了一个批量删除的模板却不知道怎么传递参数 作者: hainuo 於 二月 03, 2008, 08:16:05 下午 解决了。。
原来并不需要用单独的隐藏域来传递的。只要在 程式碼: <table border = 1 > 这里面将checkbox的属性中设置name="id[]"就行 只要选择了就会提交。。然后在action类中就可以用以下代码了<tr> <th style=20%>选择</th> <th style=20% >标题</th> <th style=20%>游客</th> <th style=40%>ip</th> </tr> {foreach from=$allTest item=test} <tr> <td > <input type="checkbox" class="checkbox" name="id[]" value="{$test->getId()}" /> </td> <td > {$test->getTitle()} </td> <td > {$test->getAuthor()} </td> <td > {$test->getClientip()} </td> </tr> {/foreach} <tr> <td > <input class="checkbox" type="checkbox" name="all" id="all" value="1" onclick="CheckAll('listtest');" /> </td> 程式碼: $id = $this->_request->getValue("id"); 当然 这种方法由于他是逐条删除 对于数据库的执行时间长 不如用 foreach ($id as $key){ var_dump("$key"); $tests= new tests(); $tests->deleteTestById($key); } 程式碼: delet 这种方法好。 如果要是用这个方法的话s类dao文件的删除该如何写呢?from table in id =(1,2,3,4) |