Debugging Magento控制器动作
好的,非常准确地说,我的任务是使用一个不涉及布局、块或视图的Magento管理模块。什么都不能展示。但是,当我在模块的adminhtml控制器中调用一个操作时,Magento一直试图呈现一个布局,如果失败,就会重定向到仪表板,并显示“未能加载源代码:”等等 现在,我已经查看了FireBug的净输出,了解了一个熟悉的系统操作,比如像这样清除缓存:这也会以“未能加载的源代码:Debugging Magento控制器动作,debugging,layout,magento,block,Debugging,Layout,Magento,Block,好的,非常准确地说,我的任务是使用一个不涉及布局、块或视图的Magento管理模块。什么都不能展示。但是,当我在模块的adminhtml控制器中调用一个操作时,Magento一直试图呈现一个布局,如果失败,就会重定向到仪表板,并显示“未能加载源代码:”等等 现在,我已经查看了FireBug的净输出,了解了一个熟悉的系统操作,比如像这样清除缓存:这也会以“未能加载的源代码: 首先,这必须是一个扩展Mage_Adminhtml_controller_操作的控制器,否则我无法判断管理员是否已登录并有权
首先,这必须是一个扩展Mage_Adminhtml_controller_操作的控制器,否则我无法判断管理员是否已登录并有权操作我的控制器。其次,我没有调试系统(而且我的公司花在软件工程上的钱太便宜了),所以我必须进行调试。所以我的问题是,在不加载布局和渲染块的情况下,究竟如何调试我的代码并从Magento获得输出?我已经尝试过使用predispatch方法输出,并在predispatch结束之前退出,但我不希望在predispatch中进行任何编码。任何帮助都将不胜感激。如果您只需要添加配置面板,则可以通过system.xml完成,ACL可以通过config.xml或adminhtml.xml进行描述 您的app/etc/modules/your_Extension.xml将是
<config>
<modules>
<Your_Extension>
<active>true</active>
<codePool>local</codePool>
</Your_Extension>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<Your_Extension>
<version>0.1.0</version>
</Your_Extension>
</modules>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<extension>
<title>Extension section</title>
</extension>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
真的
地方的
您的app/code/local/your/Extension/etc/config.xml将是
<config>
<modules>
<Your_Extension>
<active>true</active>
<codePool>local</codePool>
</Your_Extension>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<Your_Extension>
<version>0.1.0</version>
</Your_Extension>
</modules>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<extension>
<title>Extension section</title>
</extension>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
0.1.0
延伸段
和app/code/local/Your/Extension/etc/system.xml
<?xml version="1.0"?>
<config>
<sections>
<extension>
<label>extension</label>
<tab>sales</tab>
<frontend_type>text</frontend_type>
<sort_order>306</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<general translate="label comment">
<comment><![CDATA[short description for one field extension]]></comment>
<label>General</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enable_extension>
<label>Activate extension</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment><![CDATA[Activation flag you can access later from code]]></comment>
</enable_extension>
</fields>
</general>
</groups>
</extension>
</sections>
</config>
延伸
出售
文本
306
1.
1.
1.
一般的
文本
1.
1.
1.
1.
激活分机
选择
adminhtml/system\u config\u source\u yesno
1.
1.
1.
1.
这就是定义一个新扩展名所需的全部内容,该扩展名在admin端有一个配置字段,并且只需要三个文件:extension.xml、config.xml和system.xml
如果管理员登录,则无需签入控制器,因为这是由ACL处理的。当Firebug说“加载源失败”时,这意味着没有数据可显示,通常在302重定向期间。在重定向中,只发送头,不发送正文。这与您的体验相符
其次,您的URL包含admin/modulename/adminhtml\u index/actionname
,它有四个部分。在Magento中,应该只有三个部分,如“路由器/控制器/动作”,哪一部分是您的额外部分
当你有正确的动作时,不要调用$this->loadLayout()->renderLayout()
,因为那样会加载布局。要输出任何其他内容,请使用:
$this->getResponse()->setBody($content);
只有傻瓜才会怪公司太穷,不适合像XDebugh这样的开源调试器。你必须知道我公司的详细情况。那么,你如何阻止一个动作发送和阻止302重定向呢?它是重定向的,因为你的URL不存在。重定向到仪表板是管理员通常处理丢失页面的方式。好的,这解决了我的问题。必须加载并呈现布局,调试后可以删除布局。谢谢