歡迎光臨, 訪客. 請先 登入註冊一個帳號.
四月 19, 2024, 09:46:51 下午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  支援  |  使用與操作  |  寻求帮助用smarty写了一个批量删除的模板却不知道怎么传递参数 « 上篇主題 下篇主題 »
頁: [1]
作者 主題: 寻求帮助用smarty写了一个批量删除的模板却不知道怎么传递参数  (閱讀 9395 次)
hainuo
新手見習
*
文章: 2


檢視個人資料
« 於: 二月 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类中如何取得这个数组啊。
已記錄
hainuo
新手見習
*
文章: 2


檢視個人資料
« 回覆文章 #1 於: 二月 03, 2008, 08:16:05 下午 »

解决了。。

原来并不需要用单独的隐藏域来传递的。只要在
程式碼:
     <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> 
  这里面将checkbox的属性中设置name="id[]"就行 只要选择了就会提交。。然后在action类中就可以用以下代码了
程式碼:
$id = $this->_request->getValue("id");
        foreach ($id as $key){
       
        var_dump("$key");
       
        $tests= new tests();
    $tests->deleteTestById($key);
       }
当然 这种方法由于他是逐条删除 对于数据库的执行时间长  不如用 
程式碼:
delet 
from table in id =(1,2,3,4)
这种方法好。 如果要是用这个方法的话s类dao文件的删除该如何写呢?
已記錄
頁: [1]
LifeType 中文開發論壇  |  支援  |  使用與操作  |  寻求帮助用smarty写了一个批量删除的模板却不知道怎么传递参数 « 上篇主題 下篇主題 »
    前往: