Created
March 24, 2010 20:53
-
-
Save kirkegaard/342784 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Backend_PageController extends Zend_Controller_Action { | |
| public function preDispatch() { | |
| $this->view->render('page/_sidebar.phtml'); | |
| } | |
| public function init() { | |
| if(!Zend_Auth::getInstance()->hasIdentity()) { | |
| return $this->_redirect('/auth/login'); | |
| } | |
| } | |
| public function getForm($id = null) { | |
| $action = '/backend/page/update'; | |
| if(isset($id)) { | |
| $action .= '/id/' . $id; | |
| } | |
| return new Backend_Form_Page(array( | |
| 'action' => $action, | |
| 'method' => 'post' | |
| )); | |
| } | |
| /** | |
| * Finds all the rows and lists them in a grid | |
| */ | |
| public function indexAction() { | |
| $this->view->pages = Doctrine_core::getTable('Model_Page')->findByIsRoot(0); | |
| } | |
| /** | |
| * Creates a new row | |
| */ | |
| public function newAction() { | |
| $form = $this->getForm(null); | |
| $this->view->form = $form; | |
| } | |
| /** | |
| * Edit a row | |
| */ | |
| public function editAction() { | |
| $form = $this->getForm($this->_getParam('id')); | |
| $row = Doctrine_core::getTable('Model_Page')->find($this->_getParam('id')); | |
| $this->view->form = $form->populate($row->toArray()); | |
| } | |
| /** | |
| * Updates a row | |
| */ | |
| public function updateAction() { | |
| $request = $this->getRequest(); | |
| $id = $this->_getParam('id', null); | |
| $method = (isset($id)) ? 'edit' : 'new'; | |
| $identity = Zend_Auth::getInstance()->getIdentity(); | |
| if(!$request->isPost()) { | |
| return $this->_helper->redirector($method); | |
| } | |
| $form = $this->getForm($id); | |
| if(!$form->isValid($request->getPost())) { | |
| $this->view->form = $form; | |
| return $this->render($method); | |
| } | |
| $row = Doctrine_core::getTable('Model_Page')->find($id); | |
| if(!$row) { | |
| $row = new Model_Page(); | |
| } | |
| $row->fromArray(array_merge( | |
| $form->getValues(), | |
| array( | |
| 'author_id' => $identity->id | |
| ) | |
| )); | |
| $row->save(); | |
| $this->_helper->redirector('index', 'page', 'backend'); | |
| } | |
| /** | |
| * Deletes a row | |
| */ | |
| public function deleteAction() { | |
| $row = Doctrine_core::getTable('Model_Page')->find($this->_getParam('id')); | |
| $row->delete(); | |
| $this->_helper->redirector('index', 'page', 'backend'); | |
| } | |
| /** | |
| * | |
| */ | |
| public function fetchAction() {} // maybe use this for a json fetch? | |
| /** | |
| * | |
| */ | |
| public function fetchAllAction() {} // maybe use this for a json fetch? | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment