Home Tutorial Php Zendframework Zend FrameWork Part-12

 
 

Zend FrameWork Part-12
Posted on: April 20, 2010 at 12:00 AM
Advertisement
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.

 

.../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:

ZF Delete

Advertisement

Related Tags for Zend FrameWork Part-12:


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.

Posted on: April 20, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com