2012-02-16 2 views

답변

1

무엇을 하든지 코어를 수정하지 않고 사용자 정의 모듈을 만들고 가능한 경우 상위 기능을 항상 호출하는지 확인하십시오. 단지 PHP는 단위 테스트 비트를 무시 http://www.magentocommerce.com/magento-connect/modulecreator.html

이반의 비디오 자습서에서 살펴보고, 그러나 그는 훨씬 비디오 중 특히 절반 방법을 설명합니다

사용 ModuleCreater이 작업을 단순화합니다.

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 핵심 모듈과 동일한 경로를 공유 할 모듈을 만드는 것입니다. –

관련 문제