如何从 magento 的管理模块加载布局

发布于 2024-12-12 13:28:13 字数 1582 浏览 1 评论 0原文

我很难为我为 Magento 构建的管理模块设置 MVC 结构。我希望做的是正确设置 design/adminhtml/layout/ppr_extension.xml 来控制页面的内容。到目前为止,我正在从 IndexController 加载 phtml 和脚本:

$this->loadLayout();
$this->_setActiveMenu('ppr_menu/first_page');
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('ppr/ppr_1.phtml'));
$loadSimple = $this->getLayout()->getBlock('head')->addJs('ppr/load.simple.js');
$this->_addJs($loadSimple);
$this->renderLayout();

我想从配置 xml 加载它,但由于某种原因我无法完成这项工作。我想这与我的包结构有关,但我看不到它!

模板文件存在于 design/adminhtml/default/MyPackage/ppr_1.phtml

我尝试将其添加到代码/local/MyPackage/PPR/etc/config.xml

<adminhtml>
    <menu> ... </menu>

     <layout>
            <updates>
                <ppr_extension>
                    <file>ppr_extension.xml</file>
                </ppr_extension>
            </updates>
        </layout>
</adminhtml>

该扩展名 xml 位于 design/adminhtml/default/default/layout/ ppr_extension.xml

我在这里尝试了很多东西,例如:

<?xml version="1.0"?>
<layout version="0.1.0">
    <ppr_adminhtml_ppr_index>       
     <reference name="head">
      <action method="addJs"><script>script.js</script></action>
    </reference>

无论我往里面放什么,似乎都没有发生。我缺少什么?

我尝试将extension.xml移动到design/adminhtml/MyPackage/layout,但这也不起作用。感谢您的帮助..我脑痛!

I am having a difficult time getting the MVC structure set up for an admin module I am building for Magento. What I am hoping to do is correctly set up the design/adminhtml/layout/ppr_extension.xml to control the content of the page. So far I am loading the phtml and scripts from the IndexController :

$this->loadLayout();
$this->_setActiveMenu('ppr_menu/first_page');
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('ppr/ppr_1.phtml'));
$loadSimple = $this->getLayout()->getBlock('head')->addJs('ppr/load.simple.js');
$this->_addJs($loadSimple);
$this->renderLayout();

I want to load this from the config xml but for some reason I can not get this work. I imagine it has something to do with my package structure but I can not see it!

The template file exists in design/adminhtml/default/MyPackage/ppr_1.phtml

I tried adding this to the code/local/MyPackage/PPR/etc/config.xml

<adminhtml>
    <menu> ... </menu>

     <layout>
            <updates>
                <ppr_extension>
                    <file>ppr_extension.xml</file>
                </ppr_extension>
            </updates>
        </layout>
</adminhtml>

That extension xml is in design/adminhtml/default/default/layout/ppr_extension.xml

I tried many things in here like :

<?xml version="1.0"?>
<layout version="0.1.0">
    <ppr_adminhtml_ppr_index>       
     <reference name="head">
      <action method="addJs"><script>script.js</script></action>
    </reference>

No matter what I put in there nothing seems to happen. What am I missing?

I tried moving the extension.xml to design/adminhtml/MyPackage/layout but that didnt work either. Thanks for any help.. me brain hurts!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情旳空白 2024-12-19 13:28:13

既然您正在使用 Commerce Bug,这应该会更容易。

调试布局问题的第一步是确保正在加载布局 xml 文件。转到 Commerce Bug 中的布局选项卡,然后单击包布局链接。在那里查找您的自定义 XML。如果您没有看到它,则意味着您的 XML 没有被加载,您应该集中精力在 config.xml 中获取正确的 XML,并将文件放在正确的位置。

另外,请考虑根本不需要使用布局 xml。管理控制台开发人员将其用于外壳和一些神奇的小部件功能,但管理中的很多内容只是在控制器操作中添加的块,或在其他块中添加的块。使用 PHP 生成块对象并不丢人。

This should be easier now that you're using Commerce Bug.

The first step to debugging a layout problem is to make sure that your layout xml file is being loaded. Go to the layout tab in Commerce Bug and click on the Package Layout link. Look for your custom XML there. If you don't see it that means your XML isn't being loaded, and you should concentrate on getting the right XML in your config.xml, and getting your file in the right location.

Also, consider that the there's no need to use layout xml at all. The Admin Console developers use it for the outer shell and for some of the magic widget features, but there's a lot of stuff in the admin that's just blocks added in controller actions, or blocks added in other blocks. There's no shame in using PHP to generate your block objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文