Public Member Functions | |
indexAction () | |
newAction () | |
editAction () | |
saveAction () | |
deleteAction () | |
Protected Member Functions | |
_initAction () | |
_isAllowed () |
Definition at line 35 of file BlockController.php.
_initAction | ( | ) | [protected] |
Init actions
Definition at line 42 of file BlockController.php.
00043 { 00044 // load layout, set active menu and breadcrumbs 00045 $this->loadLayout() 00046 ->_setActiveMenu('cms/block') 00047 ->_addBreadcrumb(Mage::helper('cms')->__('CMS'), Mage::helper('cms')->__('CMS')) 00048 ->_addBreadcrumb(Mage::helper('cms')->__('Static Blocks'), Mage::helper('cms')->__('Static Blocks')) 00049 ; 00050 return $this; 00051 }
_isAllowed | ( | ) | [protected] |
Check the permission to run it
Reimplemented from Mage_Adminhtml_Controller_Action.
Definition at line 188 of file BlockController.php.
00189 { 00190 return Mage::getSingleton('admin/session')->isAllowed('cms/block'); 00191 }
deleteAction | ( | ) |
Delete action
Definition at line 152 of file BlockController.php.
00153 { 00154 // check if we know what should be deleted 00155 if ($id = $this->getRequest()->getParam('block_id')) { 00156 $title = ""; 00157 try { 00158 // init model and delete 00159 $model = Mage::getModel('cms/block'); 00160 $model->load($id); 00161 $title = $model->getTitle(); 00162 $model->delete(); 00163 // display success message 00164 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully deleted')); 00165 // go to grid 00166 $this->_redirect('*/*/'); 00167 return; 00168 00169 } catch (Exception $e) { 00170 // display error message 00171 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00172 // go back to edit form 00173 $this->_redirect('*/*/edit', array('block_id' => $id)); 00174 return; 00175 } 00176 } 00177 // display error message 00178 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('Unable to find a block to delete')); 00179 // go to grid 00180 $this->_redirect('*/*/'); 00181 }
editAction | ( | ) |
Edit CMS block
Definition at line 75 of file BlockController.php.
00076 { 00077 // 1. Get ID and create model 00078 $id = $this->getRequest()->getParam('block_id'); 00079 $model = Mage::getModel('cms/block'); 00080 00081 // 2. Initial checking 00082 if ($id) { 00083 $model->load($id); 00084 if (! $model->getId()) { 00085 Mage::getSingleton('adminhtml/session')->addError(Mage::helper('cms')->__('This block no longer exists')); 00086 $this->_redirect('*/*/'); 00087 return; 00088 } 00089 } 00090 00091 // 3. Set entered data if was error when we do save 00092 $data = Mage::getSingleton('adminhtml/session')->getFormData(true); 00093 if (! empty($data)) { 00094 $model->setData($data); 00095 } 00096 00097 // 4. Register model to use later in blocks 00098 Mage::register('cms_block', $model); 00099 00100 // 5. Build edit form 00101 $this->_initAction() 00102 ->_addBreadcrumb($id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block'), $id ? Mage::helper('cms')->__('Edit Block') : Mage::helper('cms')->__('New Block')) 00103 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_block_edit')->setData('action', $this->getUrl('*/cms_block/save'))) 00104 ->renderLayout(); 00105 }
indexAction | ( | ) |
Index action
Definition at line 56 of file BlockController.php.
00057 { 00058 $this->_initAction() 00059 ->_addContent($this->getLayout()->createBlock('adminhtml/cms_block')) 00060 ->renderLayout(); 00061 }
newAction | ( | ) |
Create new CMS block
Definition at line 66 of file BlockController.php.
00067 { 00068 // the same form is used to create and edit 00069 $this->_forward('edit'); 00070 }
saveAction | ( | ) |
Save action
Definition at line 110 of file BlockController.php.
00111 { 00112 // check if data sent 00113 if ($data = $this->getRequest()->getPost()) { 00114 // init model and set data 00115 $model = Mage::getModel('cms/block'); 00116 $model->setData($data); 00117 00118 // try to save it 00119 try { 00120 // save the data 00121 $model->save(); 00122 // display success message 00123 Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Block was successfully saved')); 00124 // clear previously saved data from session 00125 Mage::getSingleton('adminhtml/session')->setFormData(false); 00126 00127 // check if 'Save and Continue' 00128 if ($this->getRequest()->getParam('back')) { 00129 $this->_redirect('*/*/edit', array('block_id' => $model->getId())); 00130 return; 00131 } 00132 // go to grid 00133 $this->_redirect('*/*/'); 00134 return; 00135 00136 } catch (Exception $e) { 00137 // display error message 00138 Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 00139 // save data in session 00140 Mage::getSingleton('adminhtml/session')->setFormData($data); 00141 // redirect to edit form 00142 $this->_redirect('*/*/edit', array('block_id' => $this->getRequest()->getParam('block_id'))); 00143 return; 00144 } 00145 } 00146 $this->_redirect('*/*/'); 00147 }