Пример #1
0
 public function addAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Add');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         // form validation
         if ($form->isValid($formData)) {
             // collecting the data from user intput
             $dataArray = array('artist' => $form->getValue('artist'), 'title' => $form->getValue('title'), 'price' => $form->getValue('price'));
             //commented after passing
             //$artist = $form->getValue('artist');
             //$title = $form->getValue('title');
             //$albums = new Model_Albums();
             // some db related stuff
             $albums = new Application_Model_DbTable_Albums();
             $albums->addAlbum($dataArray);
             // after success redirect to index action
             $this->_helper->redirector('index');
         } else {
             // if any validation erros,
             // populate the form with previouis data
             $form->populate($formData);
         }
     }
 }
Пример #2
0
 public function editAction()
 {
     $form = new Application_Form_Album();
     $form->submit->setLabel('Save');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $artist = $form->getValue('artist');
             $title = $form->getValue('title');
             $id = (int) $form->getValue('id');
             $albums = new Application_Model_DbTable_Albums();
             $albums->updateAlbum($id, $artist, $title);
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $albums = new Application_Model_DbTable_Albums();
             $form->populate($albums->getAlbum($id));
         }
     }
 }
 public function modifierAction()
 {
     $form = new Application_Form_Album();
     $form->envoyer->setLabel('Sauvegarder');
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $id = $form->getValue('id');
             $artiste = $form->getValue('artiste');
             $titre = $form->getValue('titre');
             $albums = new Application_Model_DbTable_Albums();
             $albums->modifierAlbum($id, $artiste, $titre);
             $this->_helper->redirector('index');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = $this->_getParam('id', 0);
         if ($id > 0) {
             $albums = new Application_Model_DbTable_Albums();
             $form->populate($albums->obtenirAlbum($id));
         }
     }
 }