_user= new User(); $this->_flashmessenger= $this->_helper->getHelper('FlashMessenger'); $this->view->message= $this->_flashmessenger; } public function indexAction(){ $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Some errors detect in your form. Check and submit again.'); $this->_forward('list'); } public function saveAction() { $this->_helper->removeHelper('viewRenderer'); if ( $this->_request->isPost() ) { $user= $this->_user->valid( $this->_request->getPost('data') ); if ( $this->_user->hasErrors() ){ $data= array('errors' => $this->_user->getErrors(), 'user' => $user ); $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Some errors detect in your form. Check and submit again.'); $this->_forward('form',null,null,$data); return ; } if(isset($user['user_id'])) { $this->_user->update($user, $user['user_id']); } else{ $this->_user->insert($user); } } } public function addAction() { $this->_forward('form','user','admin'); return; } public function editAction() { $id= (int) $this->_request->getParam('id', 0); /* * If Get Param is a number * Trying to retrive data with this id and paste to form * Else error send to index */ if( $id !== 0 ){ $where = $this->_user->getAdapter()->quoteInto('user_id = ?', $id); $data= $this->_user->fetchRow($where); if( !is_null($data) ){ $this->_forward('form','user','admin', array('data'=>$data->toArray())); return; } } $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('You are trying to access an inexistant record'); $this->_redirect('/admin/user/'); } public function formAction() { $data= $this->_request->getParam('data', null); if( is_null($data) ){ $data= $this->_user->createRow()->toArray(); } $this->view->data= $data; Zend_Loader::loadClass('Blog'); $blogs= new Blog(); $this->view->blogs= $blogs->getIdNameList(3); $this->_locale= Zend_Registry::get('locale'); $this->view->languages= $this->_locale->getLanguageTranslationList(); $this->view->timezones= $this->_locale->getTranslationList('timezone'); ksort($this->view->languages); asort($this->view->timezones); } public function deleteAction() { $ids= (array)$this->_request->getParam('id', 0); if ( $ids[0] === 0 ) { $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Illegal access to access delete action'); $this->_redirect('/admin/user/'); } try { $this->_user->delete($ids); $this->_flashmessenger->setNamespace('succes'); $this->_flashmessenger->addMessage('Items deleted : '.$e); $this->_redirect('/admin/user/list'); } catch (Zend_Db_Exception $e) { $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Unable to delete selected Items : '.$e); $this->_redirect('/admin/user/'); } } public function listAction() { $data= $this->_user->fetchAll()->toArray(); foreach ( $data as $key => $item ) { $data[$key]['href_edit']= $this->view->url(array('action'=>'edit','id'=>$item['user_id'])); $data[$key]['href_delete']= $this->view->url(array('action'=>'delete','id'=>$item['user_id'])); } $this->view->data= $data; } public function jsonListAction(){ Zend_Loader::loadClass('Zend_Json'); $this->_helper->removeHelper('viewRenderer'); $data= $this->_user->fetchAll()->toArray(); $responseJSON = Zend_Json::encode($data); $this->getResponse()->setHeader('Content-Type', 'text/plain'); $this->getResponse()->setBody($responseJSON); } } ?>