2013-04-03 27 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立即替换内容区域。上面的完整解释和一些建议。 –