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 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路