Codeigniter:如何通过FORM传递动态ID值

时间:2014-03-05 12:04:31

标签: php forms codeigniter

我有以下动态生成div集,它使用其信息和图像加载网上商店的项目,我需要点击“btn_read”将$ row-> itemcode传递给控制器​​,我该怎么办它

     <?php $this->load->helper('url'); 


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>diluks eCommerce - Home</title>
      <link href="<?php echo base_url();?>Public/scripts/style.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
   <form action="<?php echo base_url();?>index.php/welcome_controller" method="post">
      <div class="container">
          <?php 
$userpermission = $this->session->userdata('userpermission');

if($userpermission==1){
   include 'header-admin.php'; 
}
else if($userpermission==2){
   include 'header-user.php'; 
}
else{
include 'header-guest.php';}

 ?>
         <div class="level3 clearfix">
            <?php include 'shopping-sidebar.php'; ?>
            <div class="body-content">

               <div class="image-slider">
                  <img src="<?php echo base_url();?>Public/img/main-img.png" width="785" height="220" />
               </div>
               <div class="seperate-space">
                  <div class="separate-title"><a class="bold-captions">Latest Picks</a>
                  </div>
               </div>
               <div class="items">
                <?php foreach($latestproducts as $row): ?>
   <div class="item-holder">
      <form method="POST" action="<?php echo base_url();?>index.php/Idpasser_controller/toReadMore">
            <input name="item-code" type="hidden" value="<?php echo $row->itemcode ?>" />
            <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
               <tr>
                  <td class="item-info-title" align="center" height="34px"><?php echo $row->itemname; ?></td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="230px">
                     <img src="<?php echo base_url();?>Public/uploads/<?php echo $row->itemimg; ?>" width="256" height="230" />
                  </td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="34px">$<?php echo $row->itemprice; ?></td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="35px"><input type="submit" name="btn_read" class="readbtn" value="Read More" /></td>
               </tr>
            </table>
      </form>
   </div>
<?php endforeach ?> 

               </div>
            </div>
         </div>
         <div style="clear:both"></div>
         <div class="level4">
            <div class="footer-area">
               <div class="lined-space"></div>
               <div class="site-map" align="left">
                  <table>
                     <tr>
                        <td class="footer-text"><a href="#">About Us</a></td>
                        <td class="footer-text"><a href="#">Facebook</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">Contact Us</a></td>
                        <td class="footer-text"><a href="#">Twitter</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">FAQs</a></td>
                        <td class="footer-text"><a href="#">Terms & Conditions</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">Help</a></td>
                     </tr>
                  </table>
               </div>
               <div class="developer-info">
                  <a class="developers-text">Designed & Developed By Diluks Software Solutions.</a>
               </div>
            </div>
         </div>
      </div>
      </form>
   </body>
</html>

1 个答案:

答案 0 :(得分:1)

用表格包裹你的表并添加一个字段来传递项目代码,如

<?php foreach($latestproducts as $row): ?>
   <div class="item-holder">
      <form method="POST" action="<?php echo site_url("controller/method") ?>">
            <input name="item-code" type="hidden" value="<?php echo $row->itemcode ?>" />
            <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
               <tr>
                  <td class="item-info-title" align="center" height="34px"><?php echo $row->itemname; ?></td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="230px">
                     <img src="<?php echo base_url();?>Public/uploads/<?php echo $row->itemimg; ?>" width="256" height="230" />
                  </td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="34px">$<?php echo $row->itemprice; ?></td>
               </tr>
               <tr>
                  <td class="item-info" align="center" height="35px"><input type="submit" name="btn_read" class="readbtn" value="Read More" /></td>
               </tr>
            </table>
      </form>
   </div>
<?php endforeach ?> 

注意:用您的控制器和方法替换表单操作。

希望这会有所帮助:)