Share on Google+Share on Google+

Zend FrameWork Part-12


This is the last installment of the ZF tutorial and in this page we will study how to delete any record. In next tutorial we will study about few basic and advance features of ZF.

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.




public function deleteAction()


$this->view->title = "Delete Book";


if ($this->getRequest()->isPost()) {

$del = $this->getRequest()->getPost('del');

if ($del == 'Yes') {

$id = $this->getRequest()->getPost('id');

$books = new Application_Model_DbTable_Books();





else {

$id = $this->_getParam('id', 0);

$books = new Application_Model_DbTable_Books();

$this->view->book = $books->getBook($id);





<p>Are you sure that you want to delete

'<?php echo $this->escape($this->book['title']); ?>' by

'<?php echo $this->escape($this->book['author']); ?>'?


<form action="<?php echo $this->url(array('action'=>'delete')); ?>" method="post">


<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" />





ZF Delete


Posted on: April 20, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null