自定义模块的 Magento 配置 - 如何使用控制器/布局等来显示弹出窗口?
我曾尝试过问这个问题,但收效甚微。
我正在编写一个自定义模块。自定义模块具有配置方面。在该配置中,我想弹出一个窗口,其中包含用户输入更多信息的字段(而不是将这些字段直接显示在配置屏幕上)。
因此,我在配置屏幕上有一个按钮,如果按下该按钮,则会打开这个新窗口(使用 javascript 的 window.open)。为了测试该机制,我将要打开的文件放在 Magento 安装的根目录中,这很好。但显然我需要将该文件放在其他地方。因此,我没有打开 abc.html,而是使用 javascript 打开 /index.php/myfrontname/mycontroller/myaction (我不想在我的 URL 中包含 index.php,但这完全是另一回事)。
首先,将 url 从纯 html 文件更改为 frontname/controller/action 结构是否正确?
假设是这样,我在弹出的窗口中没有得到我期望的内容。我得到一个 Magento 外观页面(我正在使用演示数据),左右列上有客户服务/迷你购物车等位,页面中间没有任何内容。我根本不想在页面上显示任何内容 - 我想显示我的 html,而且只显示我的 html。
在设置以下内容时,我一直使用艾伦·斯托姆的文档作为我的来源,但我显然遗漏了一些东西(或者很多!)。
我的JS正在“/index.php/myfrontname/moreDetails/moredetails”上执行window.open,以下是我认为与此问题相关的文件:
config.xml:
<config>
...
<adminhtml>
<layout>
<updates>
<mymodule>
<file>mymodule_moredetails.xml</file>
</mymodule>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/MyPackage/MyModule/ /MoreDetailsController.php:app/design/adminhtml/default/default/layout/mymodule_moredetails.xml:app/code/local/MyPackage/MyModule/Block/Adminhtml/System/Config/MoreDetails.php:app/design/adminhtml/
<?php
class MyPackage_MyModule_MoreDetailsController extends Mage_Core_Controller_Front_Action
{
public function moredetailsAction()
{
$this->loadLayout(); // I'm still not clear as to what layout this loads.
$this->renderLayout();
}
}
控制器
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_mycontroller_myaction>
<reference name="root">
<block type="mymodule/adminhtml_system_config_moreDetails" name="root"/>
</reference>
</mymodule_mycontroller_myaction>
</layout>
<?php
class Mypackage_MyModule_Block_Adminhtml_System_Config_MoreDetails extends Mage_Core_Block_Template // also tried extending Mage_Core_Block_Text
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('mypackage/system/config/more_details.phtml');
}
return $this;
}
}
default/default/mypackage/system/config/more_details.phtml:
<HTML>
...
</HTML>
感谢您的帮助。
I have tried asking this question in bits, but with limited success.
I am writing a custom module. The custom module has a configuration aspect. In that configuration, I want to pop up a window that contains fields where the user enters further information (rather than have that those fields directly on the configuration screen).
So I have a button on the configuration screen that, if pressed, opens this new window (using javascript's window.open). Just to test the mechanism, I put the file to be opened in the root of my Magento installation and that was fine. But clearly I will need to put that file somewhere else. So instead of opening abc.html, I had the javascript open /index.php/myfrontname/mycontroller/myaction (I'd rather not have index.php in my URLs, but that's another thing altogether).
Firstly, is changing the url from a plain html file to a frontname/controller/action structure the correct thing to do?
Assuming it is, I do not get the content I was expecting on the window that pops up. I get a Magento looking page (I am using the demo data) with the customer service / mini cart etc bits on the left and right columns, and nothing in the middle of the page. I don't want any of this on the page at all - I want to show my html, and only my html.
I have been using Alan Storm's documents as my source when setting up the following, but I am clearly missing something (or quite a lot!).
My JS is doing a window.open on "/index.php/myfrontname/moreDetails/moredetails", and here are what I think are the relevant files for this issue:
config.xml:
<config>
...
<adminhtml>
<layout>
<updates>
<mymodule>
<file>mymodule_moredetails.xml</file>
</mymodule>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/MyPackage/MyModule/controllers/MoreDetailsController.php:
<?php
class MyPackage_MyModule_MoreDetailsController extends Mage_Core_Controller_Front_Action
{
public function moredetailsAction()
{
$this->loadLayout(); // I'm still not clear as to what layout this loads.
$this->renderLayout();
}
}
app/design/adminhtml/default/default/layout/mymodule_moredetails.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_mycontroller_myaction>
<reference name="root">
<block type="mymodule/adminhtml_system_config_moreDetails" name="root"/>
</reference>
</mymodule_mycontroller_myaction>
</layout>
app/code/local/MyPackage/MyModule/Block/Adminhtml/System/Config/MoreDetails.php:
<?php
class Mypackage_MyModule_Block_Adminhtml_System_Config_MoreDetails extends Mage_Core_Block_Template // also tried extending Mage_Core_Block_Text
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('mypackage/system/config/more_details.phtml');
}
return $this;
}
}
app/design/adminhtml/default/default/mypackage/system/config/more_details.phtml:
<HTML>
...
</HTML>
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的控制器是前端控制器,这意味着它正在加载前端 XML 文件(而不是您自己的)。首先,让你的控制器从
Mage_Adminhtml_Controller_Action
继承,而不是Mage_Core_Controller_Front_Action
。接下来,请发布配置文件中为控制器设置路由的部分。
好的,将您的
块切换为
。以下是 adminhtml 中的相关块,可为您提供参考:
当您执行此操作时,您应该使用 adminhtml XML 布局文件,并希望能获得更好的结果。如果没有,请告诉我,我们会继续:)
Your controller is a frontend controller, which means that it is loading the frontend XML files (as opposed to your own). First things first, have your controller descend from
Mage_Adminhtml_Controller_Action
, rather thanMage_Core_Controller_Front_Action
.Next, please post the part of your config file where you set up the routes for the controller.
Okay, switch your
<use>standard</use>
block to<use>admin</use>
. Here's the relevant block from adminhtml to give you a point of reference:When you do this, you should be using your adminhtml XML layout file and hopefully will have better results. If not, let me know and we'll keep going :)