Mage_Adminhtml_Cms_PageController Class Reference

Inheritance diagram for Mage_Adminhtml_Cms_PageController:

Mage_Adminhtml_Controller_Action Mage_Core_Controller_Varien_Action

List of all members.

Public Member Functions

 indexAction ()
 newAction ()
 editAction ()
 saveAction ()
 deleteAction ()

Protected Member Functions

 _initAction ()
 _isAllowed ()


Detailed Description

Definition at line 35 of file PageController.php.


Member Function Documentation

_initAction (  )  [protected]

Init actions

Returns:
Mage_Adminhtml_Cms_PageController

Definition at line 43 of file PageController.php.

00044     {
00045         // load layout, set active menu and breadcrumbs
00046         $this->loadLayout()
00047             ->_setActiveMenu('cms/page')
00048             ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS'))
00049             ->_addBreadcrumb(Mage::helper('cms')->__('Manage Pages'), Mage::helper('cms')->__('Manage Pages'))
00050         ;
00051         return $this;
00052     }

_isAllowed (  )  [protected]

Check the permission to run it

Returns:
boolean

Reimplemented from Mage_Adminhtml_Controller_Action.

Definition at line 210 of file PageController.php.

00211     {
00212         return Mage::getSingleton('admin/session')->isAllowed('cms/page');
00213     }

deleteAction (  ) 

Delete action

Definition at line 172 of file PageController.php.

00173     {
00174         // check if we know what should be deleted
00175         if ($id = $this->getRequest()->getParam('page_id')) {
00176             $title = "";
00177             try {
00178                 // init model and delete
00179                 $model = Mage::getModel('cms/page');
00180                 $model->load($id);
00181                 $title = $model->getTitle();
00182                 $model->delete();
00183                 // display success message
00184                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Page was successfully deleted'));
00185                 // go to grid
00186                 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'success'));
00187                 $this->_redirect('*/*/');
00188                 return;
00189 
00190             } catch (Exception $e) {
00191                 Mage::dispatchEvent('adminhtml_cmspage_on_delete', array('title' => $title, 'status' => 'fail'));
00192                 // display error message
00193                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00194                 // go back to edit form
00195                 $this->_redirect('*/*/edit', array('page_id' => $id));
00196                 return;
00197             }
00198         }
00199         // display error message
00200         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a page to delete'));
00201         // go to grid
00202         $this->_redirect('*/*/');
00203     }

editAction (  ) 

Edit CMS page

Definition at line 76 of file PageController.php.

00077     {
00078         // 1. Get ID and create model
00079         $id = $this->getRequest()->getParam('page_id');
00080         $model = Mage::getModel('cms/page');
00081 
00082         // 2. Initial checking
00083         if ($id) {
00084             $model->load($id);/*die('<br>#stop');*/
00085             if (! $model->getId()) {
00086                 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This page no longer exists'));
00087                 $this->_redirect('*/*/');
00088                 return;
00089             }
00090         }
00091 //print '<pre>';var_dump($model->getData());
00092         // 3. Set entered data if was error when we do save
00093         $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
00094         if (! empty($data)) {
00095             $model->setData($data);
00096         }
00097 
00098         // 4. Register model to use later in blocks
00099         Mage::register('cms_page', $model);
00100 
00101         // 5. Build edit form
00102         $this->_initAction()
00103             ->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Page') : Mage::helper('cms')->__('New Page'), $id ? Mage::helper('cms')->__('Edit Page') : Mage::helper('cms')->__('New Page'))
00104             ->_addContent($this->getLayout()->createBlock('adminhtml/cms_page_edit')->setData('action', $this->getUrl('*/cms_page/save')))
00105             ->_addLeft($this->getLayout()->createBlock('adminhtml/cms_page_edit_tabs'));
00106 
00107         if (Mage::app()->getConfig()->getModuleConfig('Mage_GoogleOptimizer')->is('active', true)
00108             && Mage::helper('googleoptimizer')->isOptimizerActiveForCms()) {
00109             $this->_addJs($this->getLayout()->createBlock('googleoptimizer/js')->setTemplate('googleoptimizer/js.phtml'));
00110         }
00111         $this->renderLayout();
00112     }

indexAction (  ) 

Index action

Definition at line 57 of file PageController.php.

00058     {
00059         $this->_initAction()
00060             ->_addContent($this->getLayout()->createBlock('adminhtml/cms_page'))
00061             ->renderLayout();
00062     }

newAction (  ) 

Create new CMS page

Definition at line 67 of file PageController.php.

00068     {
00069         // the same form is used to create and edit
00070         $this->_forward('edit');
00071     }

saveAction (  ) 

Save action

Definition at line 117 of file PageController.php.

00118     {
00119         // check if data sent
00120         if ($data = $this->getRequest()->getPost()) {
00121             // init model and set data
00122             $model = Mage::getModel('cms/page');
00123 
00124 //            if ($id = $this->getRequest()->getParam('page_id')) {
00125 //                $model->load($id);
00126 //                if ($id != $model->getId()) {
00127 //                    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('The page you are trying to save no longer exists'));
00128 //                    Mage::getSingleton('adminhtml/session')->setFormData($data);
00129 //                    $this->_redirect('*/*/edit', array('page_id' => $this->getRequest()->getParam('page_id')));
00130 //                    return;
00131 //                }
00132 //            }
00133 
00134             $model->setData($data);
00135 
00136             Mage::dispatchEvent('cms_page_prepare_save', array('page' => $model, 'request' => $this->getRequest()));
00137 
00138             // try to save it
00139             try {
00140                 // save the data
00141                 $model->save();
00142 
00143                 // display success message
00144                 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Page was successfully saved'));
00145                 // clear previously saved data from session
00146                 Mage::getSingleton('adminhtml/session')->setFormData(false);
00147                 // check if 'Save and Continue'
00148                 if ($this->getRequest()->getParam('back')) {
00149                     $this->_redirect('*/*/edit', array('page_id' => $model->getId()));
00150                     return;
00151                 }
00152                 // go to grid
00153                 $this->_redirect('*/*/');
00154                 return;
00155 
00156             } catch (Exception $e) {
00157                 // display error message
00158                 Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
00159                 // save data in session
00160                 Mage::getSingleton('adminhtml/session')->setFormData($data);
00161                 // redirect to edit form
00162                 $this->_redirect('*/*/edit', array('page_id' => $this->getRequest()->getParam('page_id')));
00163                 return;
00164             }
00165         }
00166         $this->_redirect('*/*/');
00167     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:11 2009 for Magento by  doxygen 1.5.8