_blog= new Blog(); $this->_flashmessenger= $this->_helper->getHelper('FlashMessenger'); $this->view->message= $this->_flashmessenger; $this->_date= Zend_Registry::get('date'); } public function indexAction() { } public function saveAction() { $this->_helper->removeHelper('viewRenderer'); if ( $this->_request->isPost() ) { $blog= $this->_blog->valid( $this->_request->getPost('data') ); if ( $this->_blog->hasErrors() ){ $data= array('errors' => $this->_blog->getErrors(), 'blog' => $blog ); $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Some errors detect in your form. Check and submit again.'); $this->_forward('form',null,null,$data); return ; } try { if(isset($blog['blog_id'])) { $this->_blog->update($blog, $blog['blog_id']); $this->_flashmessenger->setNamespace('success'); $this->_flashmessenger->addMessage('Blog updated.'); } else{ $this->_blog->insert($blog); $this->_flashmessenger->setNamespace('success'); $this->_flashmessenger->addMessage('Blog created.'); } $this->_redirect('/admin/blog/list'); } catch (Zend_Db_Exception $e) { die($e); } } } public function addAction() { $this->_forward('form','blog','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->_blog->getAdapter()->quoteInto('blog_id = ?', $id); $data= $this->_blog->fetchRow($where); if( !is_null($data) ){ $this->_forward('form','blog','admin', array('data'=>$data->toArray())); return; } } $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('You are trying to access an inexistant record'); $this->_redirect('/admin/blog/'); } public function formAction() { $data= $this->_request->getParam('data', null); if( is_null($data) ){ $data= $this->_blog->createRow()->toArray(); } $this->view->data= $data; } 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/blog/'); } try { $this->_blog->delete($ids); $this->_flashmessenger->setNamespace('succes'); $this->_flashmessenger->addMessage('Items deleted : '.$e); $this->_redirect('/admin/blog/list'); } catch (Zend_Db_Exception $e) { $this->_flashmessenger->setNamespace('error'); $this->_flashmessenger->addMessage('Unable to delete selected Items : '.$e); $this->_redirect('/admin/blog/'); } } public function listAction() { $data= $this->_blog->fetchAll()->toArray(); foreach ( $data as $key => $item ) { $this->_date->set($item['blog_updated']); $this->_date->setTimezone('Europe/Paris'); //USER SETTINGS $data[$key]['blog_updated']= $this->_date; $data[$key]['href_edit']= $this->view->url(array('action'=>'edit','id'=>$item['blog_id'])); $data[$key]['href_delete']= $this->view->url(array('action'=>'delete','id'=>$item['blog_id'])); } $this->view->data= $data; } public function jsonListAction(){ Zend_Loader::loadClass('Zend_Json'); $this->_helper->removeHelper('viewRenderer'); $data= $this->_blog->fetchAll()->toArray(); $responseJSON = Zend_Json::encode($data); $this->getResponse()->setHeader('Content-Type', 'text/plain'); $this->getResponse()->setBody($responseJSON); } } ?>