public function updateAction() { $id = $this->_request->getParam('id'); // fetch the current item $mdlMenuItem = new Application_Model_DbTable_MenuItem(); $currentMenuItem = $mdlMenuItem->find($id)->current(); // fetch its menu $mdlMenu = new Application_Model_DbTable_Menu(); $this->view->menu = $mdlMenu->find($currentMenuItem->menu_id)->current(); // create and populate the form instance $frmMenuItem = new Application_Form_MenuItem(); $frmMenuItem->setAction('/menuitem/update'); // process the postback if ($this->_request->isPost()) { if ($frmMenuItem->isValid($_POST)) { $data = $frmMenuItem->getValues(); $mdlMenuItem->updateItem($data['id'], $data['label'], $data['link']); $this->_request->setParam('menu', $data['menu_id']); return $this->_forward('index'); } } else { $frmMenuItem->populate($currentMenuItem->toArray()); } $this->view->form = $frmMenuItem; }
public function editAction() { $id = $this->_request->getParam('id'); $mdlMenu = new Application_Model_DbTable_Menu(); $frmMenu = new Application_Form_Menu(); // if this is a postback, then process the form if valid if ($this->getRequest()->isPost()) { if ($frmMenu->isValid($_POST)) { $menuName = $frmMenu->getValue('name'); $mdlMenu = new Application_Model_DbTable_Menu(); $result = $mdlMenu->updateMenu($id, $menuName); if ($result) { // redirect to the index action return $this->_forward('index'); //$this->_redirect('/menu/index'); } } } else { // fetch the current menu from the db $currentMenu = $mdlMenu->find($id)->current(); // populate the form $frmMenu->getElement('id')->setValue($currentMenu->id); $frmMenu->getElement('name')->setValue($currentMenu->name); } $frmMenu->setAction('/' . BLOGGER_NAME . '/menu/edit'); // pass the form to the view to render $this->view->form = $frmMenu; }