Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 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 addAction()
  18.     {
  19.         $form = new Application_Form_Album();
  20.         $form->submit->setLabel('Add');
  21.         $this->view->form = $form;
  22.        
  23.         if ($this->getRequest()->isPost()) {
  24.             $formData = $this->getRequest()->getPost();
  25.             if ($form->isValid($formData)) {
  26.                 $artist = $form->getValue('artist');
  27.                 $title = $form->getValue('title');
  28.                 $albums = new Application_Model_DbTable_Albums();
  29.                 $albums->addAlbum($artist, $title);
  30.                
  31.                 $this->_helper->redirector('index');
  32.             } else {
  33.                 $form->populate($formData);
  34.             }
  35.         }
  36.            
  37.     }
  38.  
  39.     public function editAction()
  40.     {
  41.         $form = new Application_Form_Album();
  42.         $form->submit->setLabel('Save');
  43.         $this->view->form = $form;
  44.        
  45.         if ($this->getRequest()->isPost()) {
  46.             $formData = $this->getRequest()->getPost();
  47.             if ($form->isValid($formData)) {
  48.                 $id = (int)$form->getValue('id');
  49.                 $artist = $form->getValue('artist');
  50.                 $title = $form->getValue('title');
  51.                 $albums = new Application_Model_DbTable_Albums();
  52.                 $albums->updateAlbum($id, $artist, $title);
  53.                
  54.                 $this->_helper->redirector('index');
  55.             } else {
  56.                 $form->populate($formData);
  57.             }
  58.         } else {
  59.             $id = $this->_getParam('id', 0);
  60.             if ($id > 0) {
  61.                 $albums = new Application_Model_DbTable_Albums();
  62.                 $form->populate($albums->getAlbum($id));
  63.             }
  64.         }
  65.        
  66.     }
  67.  
  68.     public function deleteAction()
  69.     {
  70.         if ($this->getRequest()->isPost()) {
  71.             $del = $this->getRequest()->getPost('del');
  72.             if ($del == 'Yes') {
  73.                 $id = $this->getRequest()->getPost('id');
  74.                 $albums = new Application_Model_DbTable_Albums();
  75.                 $albums->deleteAlbum($id);
  76.             }
  77.             $this->_helper->redirector('index');
  78.         } else {
  79.             $id = $this->_getParam('id', 0);
  80.             $albums = new Application_Model_DbTable_Albums();
  81.             $this->view->album = $albums->getAlbum($id);
  82.         }
  83.     }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement