Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework][ZF2]Funkcja get post
Forum PHP.pl > Forum > PHP > Frameworki
MaciekPierwszy
Witam,

przy tworzeniu akcji delete w samouczku zenda jest użyta akcja:

  1.  
  2. // module/Album/src/Album/Controller/AlbumController.php:
  3. //...
  4. // Add content to the following method:
  5. public function deleteAction()
  6. {
  7. $id = (int) $this->params()->fromRoute('id', 0);
  8. if (!$id) {
  9. return $this->redirect()->toRoute('album');
  10. }
  11.  
  12. $request = $this->getRequest();
  13. if ($request->isPost()) {
  14. $del = $request->getPost('del', 'No');
  15.  
  16. if ($del == 'Yes') {
  17. $id = (int) $request->getPost('id');
  18. $this->getAlbumTable()->deleteAlbum($id);
  19. }
  20.  
  21. // Redirect to list of albums
  22. return $this->redirect()->toRoute('album');
  23. }
  24.  
  25. return array(
  26. 'id' => $id,
  27. 'album' => $this->getAlbumTable()->getAlbum($id)
  28. );
  29. }
  30. //...


Jakim cudem funkcja $del = $request->getPost('del', 'No'); zwraca yes?questionmark.gif

Na sronie zenda znalazłem tylko następujący opis

  1. getPost(string|null $name, mixed|null $default)
  2.  
  3. Return the parameter container responsible for POST parameters or a single POST parameter.
  4.  
  5. Returns string, Zend\Stdlib\ParametersInterface, or null depending on value of $name argument.
RiE
  1. <?php
  2. // module/Album/view/album/album/delete.phtml:
  3.  
  4. $title = 'Delete album';
  5. $this->headTitle($title);
  6. ?>
  7. <h1><?php echo $this->escapeHtml($title); ?></h1>
  8.  
  9. <p>Are you sure that you want to delete
  10. '<?php echo $this->escapeHtml($album->title); ?>' by
  11. '<?php echo $this->escapeHtml($album->artist); ?>'?
  12. </p>
  13. <?php
  14. $url = $this->url('album', array(
  15. 'action' => 'delete',
  16. 'id' => $this->id,
  17. ));
  18. ?>
  19. <form action="<?php echo $url; ?>" method="post">
  20. <div>
  21. <input type="hidden" name="id" value="<?php echo (int) $album->id; ?>" />
  22. <input type="submit" name="del" value="Yes" />
  23. <input type="submit" name="del" value="No" />
  24. </div>
  25. </form>


Ostatnie dwa inputy zwracają wartość Yes lub No w zależności od tego, który zostanie naciśnięty.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.