为新的管理模块配置Magento布局 [英] Configuring Magento Layout for New Admin Module

查看:84
本文介绍了为新的管理模块配置Magento布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Magento后端中创建自定义报告;我的策略是首先让我的新模块模仿管理面板中现有的报告/销售/订单"功能,然后在我看到各个部分如何组合后进行必要的更改.我添加了新的菜单项,该模块加载了基本的管理员布局和一些面包屑,因此模块配置和控制器配置已正确设置.但是,不会加载布局块.这是问题代码.假设我在app/code/local/BULX/Reports/Block/Report/Sales/Sales/Grid.php中有相关阻止文件的副本:

I'm trying to create a custom report in the Magento back-end; my strategy is to first make my new module mimic the existing Reports/Sales/Orders functionality in the admin panel, and then make the required changes once I've seen how the pieces fit together. I've added my new menu item, and the module loads the basic admin layout and some breadcrumbs, so the module config and controller config are set up properly enough. However, layout blocks aren't loading. Here's the problem code. Assume that I have a copy of the relevant block file at app/code/local/BULX/Reports/Block/Report/Sales/Sales/Grid.php:

class BULX_Reports_IndexController extends Mage_Adminhtml_Report_SalesController { 

  public function salesAction {

  //...otherwise identical to parent class

  //should load reference to Grid block
  $gridBlock = $this->getLayout()->getBlock('report_sales_sales.grid');

  /* in original Mage module, will output Mage_Adminhtml_Block_Report_Sales_Sales_Grid
     in BULX_Report, outputs nothing. */
  echo get_class($gridBlock)."<br>";

我的配置文件具有

<global>
  <blocks>
    <bulx_reports>
      <class>BULX_Reports_Block</class>
    </bulx_reports>
  </blocks>
  ...
</global>

如果我将代码更改为

$gridBlock = $this->getLayout()->getBlock('bulx_reports/test');

在app/code/local/BULX/Reports/Block/Test.php中具有以下文件

with the following file at app/code/local/BULX/Reports/Block/Test.php

class BULX_Reports_Block_Test extends Mage_Core_Block_Abstract
{
 protected function _toHtml() {
  echo 'to html';
 }
}

我得到相同的结果:没有'to html'输出,没有来自get_class调用的输出

I get the same result: no 'to html' output, no output from the get_class call

我按照此处的建议添加了日志语句: http://www.fontis .com.au/blog/magento/magento-debugging-loading-blocks-layouts-and-config-files

I added log statements as suggested here: http://www.fontis.com.au/blog/magento/magento-debugging-loading-blocks-layouts-and-config-files

很明显,Magento在我的新模块中没有找到任何布局块. Alan Storm的教程通常会非常有用,但是我在alanstorm.com/magento_admin_controllers中找不到我需要的东西(对不起,声望不足以拥有两个超链接);据我所知,我已经完全设置了我的配置.一个困难是'report_sales_sales.grid'字符串不会出现在任何地方-那些Grids出现在管理员的很多地方,并且它们是由我未找到的结构动态构建的.

and it's clear from that Magento isn't finding any layout blocks in my new module. Alan Storm's tutorials are usually incredibly helpful, but I'm not finding what I need in alanstorm.com/magento_admin_controllers (sorry not enough reputation to have two hyperlinks); as far as I can tell, I've set up my configuration identically. A difficulty is that the 'report_sales_sales.grid' string doesn't appear anywhere-those Grids appear in lots of places in the admin, and they get built dynamically by a structure that I haven't found.

我想念什么?这是企业版1.8.谢谢!

What am I missing? This is Enterprise Edition, 1.8. Thanks!

推荐答案

  1. 一般的PHP调试技巧,从不回显"浏览器,始终是var_dump($ var).这将做一些聪明的事情,例如,我实际将布尔值false而不是空字符串打印为"false",这是我认为在这里发生的情况.

  1. General PHP debugging tip, never "echo" to the browser, always var_dump($var). This will do smart things, such as actually print out "false" for a boolean false instead of a blank string, which is what I think is happening here.

您尝试获取名为"report_sales_sales.grid"的块的可能性最大为返回false.这是因为尚未将此名称的块添加到版式中.

Your attempt to get the block named "report_sales_sales.grid" is most likely returning false. That's because a block by this name hasn't been added to The Layout.

我不确定,但是我猜是这个名称的一个块会添加到执行链中某个位置,该位置由app/design/adminhtml/default/default/layout/sales.xml

I'm not certain, but my guess is a block by this name is added somewhere in the execution chain set off by the particular layout update in app/design/adminhtml/default/default/layout/sales.xml

store_ids created_at_order 订单创建日期 Updated_at_order 订单更新日期 报告类型 笔记 订单更新日期"报告是实时的,不需要刷新统计信息.

store_ids created_at_order Order Created Date updated_at_order Order Updated Date report_type note Order Updated Date report is real-time, does not need statistics refreshing.

最有可能的是,名为sales.report.grid.container的块(其URI adminhtml/report_sales_sales对应于Mage_Adminhtml_Block_Report_Sales_Sales类)添加了一个子块(但不要在其上引用我)

Most likely, the block named sales.report.grid.container (with a URI adminhtml/report_sales_sales which coresponds to the class Mage_Adminhtml_Block_Report_Sales_Sales) adds a sub-block (but don't quote me on that)

更大的一点是,您在此处的一般方法很好,但是复制不够.对Magento页面的请求使用布局句柄"adminhtml_report_sales_sales"运行.对您页面的请求将使用诸如"adminhtml_report_index_sales"之类的布局句柄运行,这意味着上述布局块不会加载到系统中. (如果这没有任何意义,请阅读布局句柄.)

The larger point being, you general approach here was good, but you didn't copy enough. The request to the Magento page runs with the Layout handle "adminhtml_report_sales_sales". A request to your page is going to run with a Layout handle something like "adminhtml_report_index_sales", which means the above layout block doesn't get loaded into the system. (if this made no sense, read up on Layout Handles.)

您要么需要

  1. 将模块配置为使用自定义布局文件,该文件会为您的句柄添加块

  1. Configure your module to use a custom layout files that adds the block for your handles

使用local.xml进行与上述相同的操作(注意,我不确定local.xml用于管理员布局系统)

Use a local.xml to do the same as the above (caveat, I'm not sure local.xml is used for the Admin layout system)

在控制器操作中实用地添加所需的块.

Pragmatically add the needed blocks in your controller action.

这篇关于为新的管理模块配置Magento布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆