2012-02-16 6 views

答えて

1

何をしても、コアを変更しないでカスタムモジュールを作成し、可能であれば親機能を常に呼び出すようにしてください。このタスク簡素化する

使用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; 
    } 
} 
+0

動画ありがとうございます。 –

+0

あなたのためにいくつかの情報を追加しました。 – ShaunOReilly

1

すべての余分なfuncionalityはモジュールによって行わなければなりません。私は新しいコントローラで新しいモジュールを作ったことをお勧めします。

+0

これを指摘してくれてありがとう。実際、私の問題の解決策は、CatalogSearch Coreモジュールと同じルートを共有するモジュールを作成することです。 –

関連する問題