ZF Data Update in DB


 

ZF Data Update in DB

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

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) {

0

$books = new Application_Model_DbTable_Books();

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

}

1

}

}

2

.....

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

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

3

 

Output:

edit book

4

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

Ads