2013-04-03 28 views
0

所以我遇到了一個奇怪的問題。我試圖通過鎖定到與此URL對應的控制器操作的句柄來執行佈局更新:「.../index.php/admin/catalog_category/index /」。Mageneto目錄類別佈局xml句柄?

本質上,在管理面板中,當用戶單擊目錄 - >類別 - >管理類別時,這是顯示的URL。在我自己的模塊,我試圖含住使用下面的更新此控制器操作:

<layout> 
    <admin_catalog_category_index> 
     <reference name="content"> 
      <block type="categorysearch/adminhtml_categorysearch_search" name="categorysearch" /> 
     </reference> 
    </admin_catalog_category_index> 
</layout> 

我不清楚爲什麼這工作不正常的。我很難找出爲什麼我的塊沒有被添加。

感謝您提供任何幫助!

編輯: 另外,我忘了提及,在我的塊的構造函數,我只是呼應了「來到這裏」,殺的應用程序。我已經用其他手柄和控制器動作測試了該塊,以確認塊是否正確加載。我也在我用來確保XML文件被加載的xml文件中放置其他句柄。

更新 我嘗試使用由alanstorm在這個網址提供的LayoutViewer模塊:「http://alanstorm.com/layouts_blocks_and_templates」。在使用這個工具時,事實證明沒有手柄,這怎麼可能?

+0

沒有通過,Mage_Adminhtml_Catalog_CategoryController的索引行爲被稱爲響應對象。 –

+0

@EmilStewart這是一篇非常古老的文章,針對Magento的一個漂亮的舊版本進行編碼 - 如果它出於某種原因不適用於後端,我不會感到驚訝。 'admin_catalog_category_edit'就是你想要的句柄(根據我的回答) –

回答

1

看起來你正在使用錯誤的佈局句柄,雖然很容易明白爲什麼人們會因此而被絆倒。

如果我use Commerce Bug to view the layout handles(個體經營環節,商務部的Bug是商業調試擴展我創建並賣出)該頁面,我看到了下面

enter image description here

所以這是admin_catalog_category_edit,而不是admin_catalog_category_index

爲什麼edit而不是index?如果我使用Commerce Bug's Request選項卡,找到控制文件

enter image description here

,然後看指數操作方法。

#File: app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php 
public function indexAction() 
{ 
    $this->_forward('edit'); 
} 

啊哈! indexAction方法轉發到edit操作。當您轉發在Magento的請求,你說

嘿Magento的,讓我們假裝不使用這種操作方法,而不是實際的操作方法,請求做一個HTTP重定向。

假設你的佈局XML是在正確的文件,你的admin_catalog_category_index手柄變更爲admin_catalog_category_edit,你會好到哪裏去。

更新:假設,當然,你不想更新內容塊。
類別編輯頁面的另一個問題是,當頁面加載時,它用AJAX請求替換它的內容區域。當我添加了以下到local.xml

<layout> 
    <admin_catalog_category_index> 
     <reference name="content"> 
      <!-- <block type="categorysearch/adminhtml_categorysearch_search" name="categorysearch" /> --> 
      <block type="core/text" name="WednesdayApril32013"> 
       <action method="setText"> 
        <text>This is a test</text> 
       </action> 
      </block> 
     </reference> 
    </admin_catalog_category_index> 
</layout> 

文本「這是一個測試」,在頁面的源代碼(View -> Developer -> View Source在Chrome)被渲染。然而,Magento的立即使背景Ajax請求的URL像這樣

http://store.example.com/index.php/admin/catalog_category/edit/key/c184cfd77dcf298659d1cb3a31c51852/section/general/?isAjax=true 

和替換內容部分。如果我們再看看控制器

#File: app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php 
    if ($this->getRequest()->getQuery('isAjax')) { 
     // prepare breadcrumbs of selected category, if any 
     $breadcrumbsPath = $category->getPath(); 
     if (empty($breadcrumbsPath)) { 
      // but if no category, and it is deleted - prepare breadcrumbs from path, saved in session 
      $breadcrumbsPath = Mage::getSingleton('admin/session')->getDeletedPath(true); 
      if (!empty($breadcrumbsPath)) { 
       $breadcrumbsPath = explode('/', $breadcrumbsPath); 
       // no need to get parent breadcrumbs if deleting category level 1 
       if (count($breadcrumbsPath) <= 1) { 
        $breadcrumbsPath = ''; 
       } 
       else { 
        array_pop($breadcrumbsPath); 
        $breadcrumbsPath = implode('/', $breadcrumbsPath); 
       } 
      } 
     } 

     Mage::getSingleton('admin/session') 
      ->setLastViewedStore($this->getRequest()->getParam('store')); 
     Mage::getSingleton('admin/session') 
      ->setLastEditedCategory($category->getId()); 
    //   $this->_initLayoutMessages('adminhtml/session'); 
     $this->loadLayout(); 

     $eventResponse = new Varien_Object(array(
      'content' => $this->getLayout()->getBlock('category.edit')->getFormHtml() 
       . $this->getLayout()->getBlock('category.tree') 
       ->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'), 
      'messages' => $this->getLayout()->getMessagesBlock()->getGroupedHtml(), 
     )); 

     Mage::dispatchEvent('category_prepare_ajax_response', array(
      'response' => $eventResponse, 
      'controller' => $this 
     )); 

     $this->getResponse()->setBody(
      Mage::helper('core')->jsonEncode($eventResponse->getData()) 
     ); 

     return; 
    } 

我們可以這樣處理這個ajax請求是在正常佈局渲染流程之外處理的。

所以,這種額外的知識,我會創建一個事件偵聽器category_prepare_ajax_response,然後將內容添加到在

+0

嗨Alan Storm, 讓我開始說非常感謝你回覆這篇文章。我已經購買並閱讀了您的書籍「無褶皺Magento佈局」,它非常棒。我感覺自己像一個搖滾明星,你回答我的一個問題lol:p。 –

+0

對不起,有兩條評論,不小心點擊「進入」提前。商業bug看起來像一個非常棒的軟件,我必須檢查它。就解決方案而言,我確實試圖抓住「」的句柄,但該塊仍然沒有被添加(我知道我的佈局更新文件正在被加載,但因爲其他句柄正在工作)。我將深入探討這一點,但感謝你的迴應,我認爲我走在正確的軌道上。 –

+0

@EmilStewart我已經更新了我的答案 - 看起來類別編輯頁面通過ajax立即替換內容區域。上面的完整解釋和一些建議。 –