2017-02-02 1 views
0

In meiner Sicht habe ich den Link, die modale Box und Skript. Ich habe meine ID auf meinem Modal, aber ich kann es nicht auf meinem Controller senden.Senden von Daten auf Modal-Box auf mvc

Der Link:

<a href="#myModal" data-toggle="modal" id="<?php echo $salle['id_salle'];?>" data-target="#edit-modal"><span class="glyphicon glyphicon-pencil"></span></a> 

Mein modal:

<div id="edit-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
      <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
     </div> 
     <div class="modal-body edit-content"></div> 
     <div class="modal-footer"> 
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
      <button type="button" class="btn btn-primary">Save changes</button> 
     </div> 
    </div> 
</div> 

Und mein Skript:

$(document).ready(function() { 
    $('#edit-modal').on('show.bs.modal', function(e) { 
    var $modal = $(this), 
    Id = e.relatedTarget.id; 
    $.ajax({ 
     method: 'POST', 
     url: 'index.php?section=gestion-salles', 
     data: 'id_salle='+Id, 
     success: function(data) { 
     alert(data); 
     $modal.find('.edit-content').html(Id + '<?php echo $test; ?> ' + 'id= <?php echo $id; ?>'); 
     } 
    }); 
    }) 
}); 

In meinem Controller ich eine Variable definiert, $test und ich habe es wiedergefunden. Aber ich habe meine Variable $ _POST ['id_salle'] definiert, kann sie aber nicht wiederherstellen. Ich möchte es an den Controller senden und dann die Verarbeitung durchführen, aber ich kann nicht.

Vielen Dank.

+0

Schreib-Controller ordnungsgemäß in Ihrer Frage –

+0

In meinem Controller i mit include_once mein Modell nennen, und ich rufe meine Funktion des Modells. Ich habe $ id = $ _POST ['id_salle'] definiert. Und schließlich rufe ich meine Ansichten (Header, Seite und Fußzeile). – WxIpN

Antwort

0

Mein Controller:

include_once('modele/set_salles.php'); 
include_once('modele/get_salles.php'); 
include_once('controleur/modal.php'); 
if(isset($_POST['bouton'])) 
{ 
    if($_POST['titre'] !='' && $_POST['description'] !='' && $_POST['adresse'] !='' && $_POST['cp'] !=''){ 
     $tmp_name = $_FILES["photo"]["tmp_name"]; 
     $name = $_FILES["photo"]["name"]; 
set_salles(addslashes($_POST['titre']), addslashes($_POST['description']), $name, $_POST['pays'], $_POST['ville'], addslashes($_POST['adresse']), $_POST['cp'], $_POST['capacite'], $_POST['categorie']); 
     $uploads_dir = 'img/'; 
     move_uploaded_file($tmp_name, "$uploads_dir/$name"); 
    } else { 
     $remplir = '<p style="color:red">merci de remplir tous les champs</p>'; 
    } 
} 
$salles = get_salles(); 
foreach($salles as $cle => $salle) 
{ 
$salles[$cle]['titre'] = htmlspecialchars($salle['titre']); 
$salles[$cle]['description'] = nl2br(htmlspecialchars($salle['description'])); 
} 
$id = $_POST['id_salle']; 
$test = 'Hello'; 
// On affiche les page (vues) 
include_once('vue/include/header.php'); 
include_once('vue/include/navbar.php'); 
include_once('vue/gestion-salles.php'); 
include_once('vue/include/footer.php'); 
Verwandte Themen