Home Tutorial Php Zendframework ZF Data Update in DB

 
 

Share on Google+Share on Google+
ZF Data Update in DB
Posted on: May 7, 2010 at 12:00 AM
Advertisement
Editing a book and its content is identical to the adding. With the help of given coding we can edit the necessary changes. After every entry there is a link called edit which proceeds us to another page which is made for editing any record...

Edit Record in Zend Framework:

Now if someone wants to change, update or edit any record then the required settings and coding are given below, as usual the coding is different from conventional PHP coding, so go through the coding carefully and make necessary changes. Code of the section below is pretty similar with the adding section.

/application/controllers/IndexController.php

.....

public function editAction()

{

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

$this->view->headTitle($this->view->title);

$form = new Application_Form_Book();

$form->submit->setLabel('Save');

$this->view->form = $form;

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

$formData = $this->getRequest()->getPost();

if ($form->isValid($formData)) {

$id = (int)$form->getValue('id');

$author = $form->getValue('author');

$publisher = $form->getValue('publisher');

$title = $form->getValue('title');

$books = new Application_Model_DbTable_Books();

$books->updateBook($id, $author,$publisher,$title);

$this->_helper->redirector('index');

} else {

$form->populate($formData);

}

} else {

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

if ($id > 0) {

$books = new Application_Model_DbTable_Books();

$form->populate($books->getBook($id));

}

}

}

.....

../application/views/scripts/index/edit.phtml

<?php echo $this->form;?>

 

Output:

edit book

Now make necessary changes and click the save button, it will update the book table.

Advertisement

Related Tags for ZF Data Update in DB:


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: May 7, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com