Что бы вы ни делали, не модифицируйте ядро, а создайте пользовательский модуль и убедитесь, что вы всегда вызываете родительские функции, где это возможно.
Используйте ModuleCreater для упрощения этой задачи:
http://www.magentocommerce.com/magento-connect/modulecreator.html
Взгляните на видеоурок Ивана, просто проигнорируйте бит модульного тестирования php, но он все объясняет, особенно в середине видео.
http://vimeo.com/35937480
Также посмотрите на этот образец для некоторых других идей:
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-3-magento-controller-dispatch
Обе передовые практики передаются по обеим ссылкам.
Класс контроллера может выглядеть так:
class Mycompany_myMod_Adminhtml_myModController extends Mage_Adminhtml_Controller_action
{
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('custompromos/items')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
return $this;
}
public function indexAction() {
$this->_initAction()
->renderLayout();
}
public function editAction() {
$id = $this->getRequest()->getParam('id');
//Some code here
}
public function newAction() {
$this->_forward('edit');
}
public function saveAction() {
if ($data = $this->getRequest()->getPost()) {
//Some code here
}
}
public function deleteAction() {
if( $this->getRequest()->getParam('id') > 0 ) {
try {
//Some code here
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}
public function massDeleteAction() {
//Some code here
$this->_redirect('*/*/index');
}
public function massStatusAction()
{
//Some code here
$this->_redirect('*/*/index');
}
public function exportCsvAction()
{
$fileName = 'somedata.csv';
$content = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_grid')
->getCsv();
$this->_sendUploadResponse($fileName, $content);
}
public function exportXmlAction()
{
$fileName = 'somedata.xml';
$content = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_grid')
->getXml();
$this->_sendUploadResponse($fileName, $content);
}
protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
{
$response = $this->getResponse();
$response->setHeader('HTTP/1.1 200 OK','');
$response->setHeader('Pragma', 'public', true);
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
$response->setHeader('Last-Modified', date('r'));
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', strlen($content));
$response->setHeader('Content-type', $contentType);
$response->setBody($content);
$response->sendResponse();
die;
}
}