Guest User

Untitled

a guest
Dec 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2.  
  3. class IndexController extends Zend_Controller_Action
  4. {
  5.  
  6. public function init()
  7. {
  8. /* Initialize action controller here */
  9. }
  10.  
  11. public function indexAction()
  12. {
  13. $albums = new Application_Model_DbTable_Albums();
  14. $this->view->albums = $albums->fetchAll();
  15. }
  16.  
  17. public function langAction()
  18. {
  19. $lang = $this->getRequest()->getParam('lang', 'en_US');
  20. $bootstrap = $this->getInvokeArg('bootstrap');
  21. $bootstrap->bootstrap('translate');
  22. $translate = $bootstrap->getResource('translate');
  23. $translate->setLocale($lang);
  24. Zend_Registry::set('Zend_Translate', $translate);
  25. Zend_Registry::set('Zend_Locale', $lang);
  26. }
  27.  
  28. public function addAction()
  29. {
  30. $form = new Application_Form_Album();
  31. $form->submit->setLabel('Add');
  32. $this->view->form = $form;
  33.  
  34. if ($this->getRequest()->isPost()) {
  35. $formData = $this->getRequest()->getPost();
  36. if ($form->isValid($formData)) {
  37. $artist = $form->getValue('artist');
  38. $title = $form->getValue('title');
  39. $albums = new Application_Model_DbTable_Albums();
  40. $albums->addAlbum($artist, $title);
  41.  
  42. $this->_helper->redirector('index');
  43. } else {
  44. $form->populate($formData);
  45. }
  46. }
  47.  
  48. }
  49.  
  50. public function editAction()
  51. {
  52. $form = new Application_Form_Album();
  53. $form->submit->setLabel('Save');
  54. $this->view->form = $form;
  55.  
  56. if ($this->getRequest()->isPost()) {
  57. $formData = $this->getRequest()->getPost();
  58. if ($form->isValid($formData)) {
  59. $id = (int)$form->getValue('id');
  60. $artist = $form->getValue('artist');
  61. $title = $form->getValue('title');
  62. $albums = new Application_Model_DbTable_Albums();
  63. $albums->updateAlbum($id, $artist, $title);
  64.  
  65. $this->_helper->redirector('index');
  66. } else {
  67. $form->populate($formData);
  68. }
  69. } else {
  70. $id = $this->_getParam('id', 0);
  71. if ($id > 0) {
  72. $albums = new Application_Model_DbTable_Albums();
  73. $form->populate($albums->getAlbum($id));
  74. }
  75. }
  76.  
  77. }
  78.  
  79. public function deleteAction()
  80. {
  81. if ($this->getRequest()->isPost()) {
  82. $del = $this->getRequest()->getPost('del');
  83. if ($del == 'Yes') {
  84. $id = $this->getRequest()->getPost('id');
  85. $albums = new Application_Model_DbTable_Albums();
  86. $albums->deleteAlbum($id);
  87. }
  88. $this->_helper->redirector('index');
  89. } else {
  90. $id = $this->_getParam('id', 0);
  91. $albums = new Application_Model_DbTable_Albums();
  92. $this->view->album = $albums->getAlbum($id);
  93. }
  94. }
  95.  
  96.  
  97. }
Add Comment
Please, Sign In to add comment