mercredi 9 août 2017

CodeIgniter - Pass value from view to controller with clicking a button

I know here are some similiar Topics but I couldnt find a solution for my problem. I have a table where I have a delete button for every entry (in code called "wp"). When I click this button a modal opens. In this modal I want to Show some data for which I Need to pass the ID of the item I want to delete to the Controller, where i pass it to a function which includes a database query and finally Need to get the right value back to the view.

View:

  <tbody>
     <?php
        if($wps!= NULL){
          foreach($wps as $wp){
        ?>
     <tr>
        <td><?php echo $wp->type; ?></td>
        <td>....</td>            


           <a class="btn btn-default btn-icon" title="Edit" href="<?php echo site_url("myurl"); ?>"><i  class="icon icon-edit" aria-hidden="true"></i></a>
           <a class="btn btn-default btn-icon" title="Create" href="<?php echo site_url("myurl"); ?>"><i class="icon icon-add" aria-hidden="true"></i></a>
           <button value="<?php echo $wp->id; ?>" class="btn btn-default btn-icon delete" title="Delete" data-toggle="modal" data-target="#modal-delete-<?php echo $wp->id; ?>" type="button"><i class="icon icon-move-to-trash" aria-hidden="true"></i></button>

          </td>

     </tr>
     <div id="modal-delete-<?php echo $wp->id; ?>" class="modal fade" aria-labelledby="exampleModalLabel2" aria-hidden="true" role="dialog">
     <div class="modal-dialog">
        <div class="modal-content">
           <button type="button" class="close" data-dismiss="modal">
           <span aria-hidden="true">x</span>
           <span class="sr-only">Close</span>
           </button>
           <div class="modal-header">
               <h4 class="modal-title" id="exampleModalLabel2"><strong>Delete </strong><br><br>Account:&nbsp;<strong><?php echo $cus->name ?></strong><br>:&nbsp;<strong><?php echo $wp->type ?></strong><br>Service in Scope:&nbsp;<strong><?php echo $wp->sis?></strong><br>This cannot be undone. Do you want to continue?</h4>

               <ul class="content-list">
                <?php 
                    if($finding != NULL){
                    foreach($finding as $f){
                    ?>
                   <ul class="content-list"> 
                    <li class="media">
                        <div class="media-body">
                            <div class="media-heading"><?php echo $f->sis?></div>
                            <div class="media-hint"><?php echo $f->finding ?></div>
                        </div>
                    </li>
                  </div>
            <?php }} ?>


            </ul>


           </div>

           <div class="modal-footer">
              <br>
              <center>
                 <a href="<?php echo site_url("myurl"); ?>" class="btn btn-brand" title="Delete" style="width: 170px;">
                    <div align="center"><i class="icon icon-confirm" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;&nbsp;Delete</div>
                 </a>
                 <button type="button" class="btn btn-brand" title="Return" data-dismiss="modal" style="width: 170px;">
                    <div align="center"><i   class="icon icon-cancel" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;&nbsp;Return</div>
                 </button>
              </center>
           </div>
        </div>
     </div>
  </div>
   <?php }} ?>  
  </tbody>

Controller:

    $data["finding"] = $this->Model->get_findings($needed_value);

It would be great if you have an idea how i can pass the $wp->id from view to controller

Aucun commentaire:

Enregistrer un commentaire