gpt4 book ai didi

具有前端和管理功能的 Magento 模块

转载 作者:行者123 更新时间:2023-12-02 12:05:51 25 4
gpt4 key购买 nike

我目前正在为 Magento 开发一个自定义模块。我了解包、模块和路由器的基础知识,并且我已经构建了模块的前端部分。

但是我现在正在转向管理方面。然而,我对如何将管理部分添加到路由器并让它调用相关 Controller 感到有点困惑。

假设我已经创建了这些路由器...

<frontend>
<routers>
<slider>
<use>standard</use>
<args>
<module>Mypackage_Myodule</module>
<frontName>Mymodule</frontName>
</args>
</slider>
</routers>
</frontend>
<admin>
<routers>
<mymoduleadmin>
<use>admin</use>
<args>
<module>Mypackage_Myodule</module>
<frontName>Mymodule</frontName>
</args>
</mymoduleadmin>
</routers>
</admin>

我认为这两个路由器都会尝试调用controllers/IndexController.php,因此具有相同的功能?是否可以进行设置,以便我的路由器根据它们是前端还是管理来调用不同的 Controller ?这是否可能,或者我是否需要设置前端模块和管理模块?

如果这是一个男生问题,我很抱歉,但这让我有点困惑,实际上我只是想知道设置具有前端和管理功能的自定义模块的最有效方法。

最佳答案

根据区域(前端或 adminhtml),调度前端或 adminhtml 路由器。
因此,只要您为前端和 adminhtml 使用不同的 Controller 文件,前端 Controller 从 Mage_Core_Controller_Front_Action 扩展,而 adminhtml 从 Mage_Adminhtml_Controller_Action 扩展,您就不必担心弄乱它。 .

前端/Adminhtml 路由器可以定义为(只是语法):

<frontend>
<routers>
<[module]>
<use>standard</use>
<args>
<module>[Namespace]_[Module]</module>
<frontName>[module]</frontName>
</args>
</[module]>
</routers>
</frontend>
<admin>
<routers>
<[module]>
<use>admin</use>
<args>
<module>[Namespace]_[Module]</module>
<frontName>[module]</frontName>
</args>
</[module]>
</routers>
</admin>

您可以在以下位置创建前端 Controller :app/code/[codePool]/[Namespace]/[Module]/controllers/
例如:

<?php
//file: app/code/local/MagePsycho/Testmodule/controllers/IndexController.php
class MagePsycho_Testmodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction(){

}
}

为了从网址访问它:http://your-magento-url/testmodule/index/index
和 adminhtml Controller 位于:app/code/[codePool]/[命名空间]/[模块]/controllers/Adminhtml/
例如:

<?php
//file: app/code/local/MagePsycho/Testmodule/controllers/Adminhtml/IndexController.php
class MagePsycho_Testmodule_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction(){

}
}


为了从网址访问它:http://your-magento-url/testmodule/adminhtml_index/index
(可以看到Adminhtml文件夹,用于分隔adminhtml Controller )

希望这能给您一些信息。
谢谢

关于具有前端和管理功能的 Magento 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com