/** * * @param \Music\Model\Album $album * @throws \Exception */ public function saveAlbum(Album $album, $album_id) { $data = array('album_title' => $album->getAlbum_title(), 'artist_id' => $album->getArtist_id(), 'date_released' => $album->getDate_released(), 'createdby' => $this->id); // $album_id = (int) $album->getAlbum_id(); if (!$album_id) { $this->tableGateway->insert($data); } elseif ($album_id) { $this->tableGateway->update($data, array('album_id' => $album_id)); } else { throw new \Exception('Form id does not exist'); } }
/** * This function returns a form for adding an album * @return type */ public function addAction() { // //An array which populate respective artists in a select box for album // $jah = $this->getArtistTable()->fetchAll(); // $myArray = array(); // foreach ($jah as $d): // $myArray[$d->getArtistId()]= $d->getFullName(); // endforeach; // /* populate the album list with artist from the database */ $artistList = $this->getArtistTable()->artistSelectList(); //Create an instance of the form $form = new AlbumForm($artistList); //Get the request $request = $this->getRequest(); //If the request is posted if ($request->isPost()) { //Create an album object $album = new Album(); //Get the input filter to filter the form elements $form->setInputFilter($album->getInputFilter()); //Set the data and get the posted values $form->setData($request->getPost()); //If the form is valid if ($form->isValid()) { //Get the form data using the exchange array $album->exchangeArray($form->getData()); //Go to the album table and save the album $this->getAlbumTable()->saveAlbum($album); $this->flashMessenger()->addMessage(sprintf(" %s <center>Album added Successfully</center> %s", '<div class="alert alert-success">', '</div>')); // $this->flashMessenger()->getCurrentMessages(); //Redirect to the list of albums return $this->redirect()->toRoute('album', array('controller' => 'album', 'action' => 'index')); } } //return the form if the request was not posted return array('form' => $form); }