Zend Framework-12:
Delete Book:
To complete the application we have to add the deletion part as well. We will put a delete link after each entry (record) in our list page, this link will take us to other page which will ask for our confirmation. If we click the yes button then the record will be deleted from the record and if we click the no button then this will take us to the index page.
Like the add and edit function in delete function we will use Request's isPost() method. This method will determine whether we will display the confirmation page or not. We use the Application_Model_DbTable_Books model to delete the record from the table using deleteBook() method.
.../application/form/Book.php:
...
public function deleteAction(){
$this->view->title = "Delete Book"; $this->view->headTitle($this->view->title); if ($this->getRequest()->isPost()) { $del = $this->getRequest()->getPost('del'); if ($del == 'Yes') { $id = $this->getRequest()->getPost('id'); $books = new Application_Model_DbTable_Books(); $books->deleteBook($id);}
$this->_helper->redirector('index');}
else {
$id = $this->_getParam('id', 0);
$books = new Application_Model_DbTable_Books();
$this->view->book = $books->getBook($id);
}
}
...
../application/views/scripts/index/add.phtml
<
p>Are you sure that you want to delete'
<?php echo $this->escape($this->book['title']); ?>' by'
<?php echo $this->escape($this->book['author']); ?>'?</
p><
form action="<?php echo $this->url(array('action'=>'delete')); ?>" method="post"><
div> <input type="hidden" name="id" value="<?php echo $this->book['id']; ?>" /> <input type="submit" name="del" value="Yes" /> <input type="submit" name="del" value="No" /></
div></
form>
Output:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.