donglaoping9702 2011-10-27 02:50
浏览 58
已采纳

如何从magento中的admin模块加载布局

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!

  • 写回答

1条回答 默认 最新

  • dongqindu8110 2011-10-27 20:52
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化