Poster une réponse à un sujet: Framework SLIM MVC
Attention, ce sujet est un sujet ancien (2894 jours sans réponse)
Gras [b]Texte[/b] Italique [i]Italique[/i] Souligné [u]Souligné[/u] Barré [strike]Barré[/strike]
Courriel [email=nobody@nobody.org]Nom[/email] Lien [url=http://www.website.com]Texte[/url] Ancre [anchor]Nom[/anchor] Image [img]http://www.website.com/image.jpg[/img] Insérer une image en provenance du site
Aligné à gauche [align=left]Texte[/align] Centré [align=center]Texte[/align] Aligné à droite [align=right]Texte[/align] Toute la largeur [align=justify]Texte[/text]
Couleur [color=#000000]Text[/color] Mise en forme [highlight=pascal]Texte[/highlight] Widgets Emoticons :code: [:code] Convertisseur HTML vers BBCode Convertisseur Word vers BBCode
Prévisualisation Vérification de l'orthographe

Copier Coller Couper Tout sélectionner
Tout effacer Insérer la date Insérer l'heure Insérer la date et heure Insérer votre IP
Liste [list=square][item]BlaBla[/item][/list] Liste Numérotée [list=decimal][item]BlaBla[/item][/list]
Citation [quote=name]Texte[/quote] Spoiler [spoiler]James est le meurtrier![/spoiler]
Tout en majuscules [uppercase]Texte[/uppercase] Tout en minuscules [lowercase]Texte[/lowercase] l33t [l33t]Je suis un nerd[/l33t] Texte en indice [sub]Texte[/sub] Texte en exposant [sup]Texte[/sup] Taille du texte [size=8]Texte[/size]
 
ovh
(HS pour zion: tiens, le coloriseur syntaxique ne supporte pas le doctype pour le format html :oh: )
keza
Bonjour,

Je suis nouveau et je suis en train de faire une api en utilisant le framework slim j'ai du mal pour sélectionner une ligne dans un tableau pour pouvoir les afficher dans les champs:

Quelqu'un pour m'aider ..... je vous remercie de votre aide


index.php
----------------

  1. <?php 
  2. // include  
  3. require 'Slim-2.6.0/Slim/Slim.php'
  4. require './models/model.php'
  5. \Slim\Slim::registerAutoloader(); 
  6. $app = new \Slim\Slim(); 
  7. $app->get('/contacts(/:id)''getContacts'); 
  8. $app->delete('/contacts/:id','deleteContact'); 
  9. $app->put('/contacts/:id','updateContact'); 
  10. $app->run(); 
  11. function getContacts($id=null) { 
  12. $response=\Slim\Slim::getInstance()->response(); 
  13. $response->headers->set('Content-Type''application/json'); 
  14. if (!isset($id)){ 
  15. $response->setStatus(200); 
  16. echo json_encode(Contacts::find_array()); 
  17. else 
  18. if ($contact = Contacts::find_one($id)) 
  19. $response->setStatus(200); 
  20. echo json_encode($contact->as_array()); 
  21. else 
  22. $response->setStatus(404); 
  23. function deleteContact($id) { 
  24. $response=\Slim\Slim::getInstance()->response(); 
  25. $response->headers->set('Content-Type''application/json'); 
  26. $contact = Contacts::find_one($id); 
  27. if ($contact) { 
  28. $contact->delete(); 
  29. $response->setStatus(200); 
  30. }else
  31. $reponse->setStatus(404); 
  32. function updateContact($id) { 
  33. $response=\Slim\Slim::getInstance()->response(); 
  34. $response->headers->set('Content-Type''application/json'); 
  35. $contact = Contacts::find_one($id); 
  36. if ($contact) { 
  37. $contact->delete(); 
  38. $response->setStatus(200); 
  39. }else
  40. $reponse->setStatus(404); 
  41. ?>


Model.js
----------------------

  1. $.extend({ 
  2. Contact:function(id,nom,prenom,email){ 
  3. this.data={ 
  4. "id":id, 
  5. "nom":nom, 
  6. "prenom":prenom, 
  7. "email":email 
  8. }; 
  9. }); 
  10. $.Contact.getAll=function(f){ 
  11. $.getJSON("/contacts/rest/contacts",null,function(data){ 
  12. var items=[]; 
  13. $.each(data,function(i,el){ 
  14. items.push(new $.Contact(el.id,el.nom,el.prenom,el.email));  
  15. }); 
  16. f(items); 
  17. }); 
  18. };





Controller.js
-------------------

  1. $.extend({ 
  2. Controller:function(view,contacts){ 
  3. var that=this
  4. this.selection=null
  5. contacts.getAll( 
  6. function(items){ 
  7. view.updateTable(items); 
  8. }); 
  9. });



Vieuw.js
---------------------

  1. $.extend({ 
  2. View:function(){ 
  3. var form=$('#form'); 
  4. var table=$('#ct'); 
  5. var moi=this
  6. this.sel=null
  7. this.updateTable=function(contacts){ 
  8. var matable=$("#ct").children("tbody").empty(); 
  9. $.each(contacts,function(i,contact){ 
  10. matable.append("<tr data-id='"+contact.data.id+"'>" 
  11. +"<td>"+contact.data.nom+"</td>" 
  12. +"<td>"+contact.data.prenom+"</td>" 
  13. +"<td>"+contact.data.email+"</td>" 
  14. +"</tr>" 
  15. );  
  16. }); 
  17. }; 
  18. this.listeners={ 
  19. clickAjouter:function(){}, 
  20. clickEditer:function(){}, 
  21. clickSupprimer:function(){}, 
  22. clickSelection:function(){}, 
  23. clickDeselection:function(){} 
  24. }; // listeners vide par défaut, que le 
  25.    // controleur complétera pour etre notifié 
  26.    // des événements dans la vue. 
  27.   
  28. });


table.html
--------------------

  1. <html lang="en"
  2. <head
  3. <meta charset="UTF-8" /> 
  4. <title></title
  5. <link href="./css/bootstrap.css" rel="stylesheet" /> 
  6. </head
  7. <body
  8. <div class="container"
  9. <div class="row"
  10. <div class="span8"
  11. <h4>Liste des contacts </h4
  12. <hr
  13. <table id="ct" class="table table-hover table-striped table-bordered table-condensed" cellspacing="0"
  14. <thead
  15. <tr
  16. <th>Nom</th
  17. <th>Prénom</th
  18. <th>Email</th
  19. </tr
  20. </thead
  21. <tbody
  22. </tbody
  23. </table
  24. <nav></nav
  25. </div
  26. <div class="span4"
  27. <form  id="form"
  28. <h4>Contact</h4
  29. <hr
  30. <label>Prénom</label
  31. <input id="prenom" name="prenom" placeholder="Prénom"  type="text"
  32. <label>Nom</label
  33. <input id="nom" name="nom" placeholder="Nom"  type="text"
  34. <label>Email</label
  35. <input id="email" name="email" placeholder="Email"  type="text"
  36. <br
  37. <button   id="supprimer" name="spprimer" class="btn btn-danger disabled"><i class="icon-trash icon-white"></i></button
  38. <button   id="editer" name="editer" class="btn btn-primary disabled"><i class="icon-pencil icon-white"></i></button
  39. <button  id="ajouter" name="ajouter" class="btn btn-success"><i class="icon-plus icon-white"></i></button
  40. </form
  41. <div id="message"></div
  42. </div
  43. </div>  
  44. </div
  45. <!--script src="//code.jquery.com/jquery-1.11.2.min.js"></script--> 
  46. <script src="./js/jquery-1.10.1.js"></script
  47. <script src="./js/model.js"></script
  48. <script src="./js/view.js"></script
  49. <script src="./js/controller.js"></script
  50. <script
  51. var model=$.Contact; 
  52. var view=new $.View(); 
  53. var controller=new $.Controller(view,model); 
  54. </script
  55. </body
  56. </html>
Catégorie:  






Ada
CSS
Cobol
CPP
HTML
Fortran
Java
JavaScript
Pascal
Perl
PHP
Python
SQL
VB
XML
Anon URL
DailyMotion
eBay
Flickr
FLV
Google Video
Google Maps
Metacafe
MP3
SeeqPod
Veoh
Yahoo Video
YouTube
6px
8px
10px
12px
14px
16px
18px
Informaticien.be - © 2002-2024 AkretioSPRL  - Generated via Kelare
The Akretio Network: Akretio - Freedelity - KelCommerce - Votre publicité sur informaticien.be ?