问题描述
我目前正在为Magento开发自定义模块.我了解软件包,模块和路由器的基础知识,并且已经构建了模块的前端部分.
I'm currently working on a custom module for Magento. I understand the basics of Packages, Modules and Routers, and I have built the front end part of my module.
不过,我现在要谈谈管理的问题.但是,我对如何将admin部分添加到路由器并让其调用相关控制器感到有些困惑.
However I am now moving on to the admin side of things. However I'm a little bit confused by how I add the admin part to my routers and get it to call the relevant controller.
假设我已经创建了这些路由器...
Let's imagine I have created these routers...
<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,因此具有相同的功能?是否可以进行设置,以便我的路由器根据是前端还是管理员来调用不同的控制器?甚至有可能还是我需要设置一个前端模块和一个管理模块?
I presume that both these routers will attempt to call controllers/IndexController.php and therefore the same functionality? Is it possible to set things up so my routers call different controllers depending on whether they are front end or admin? Is this even possible or do I need to set up a front end module and an admin module?
对于这是一个男生的问题,我深表歉意,但是这让我有些困惑,实际上,我只想知道设置具有前端和管理功能的自定义模块的最有效方法.
I apologise if this is a School Boy question, but this has me a bit confused and in reality I just want to know the most efficient way to set up a custom module with front end and admin functionality.
推荐答案
根据区域(前端或adminhtml),调度前端或adminhtml路由器.
因此,只要您对前端和adminhtml使用不同的控制器文件,您就不必担心搞砸了,前端控制器从Mage_Core_Controller_Front_Action
& adminhtml从Mage_Adminhtml_Controller_Action
扩展.
Depending upon the area(frontend or adminhtml), frontend or adminhtml router are dispatched.
So you need not need to worry about getting it messed up as long as you are using different controller files for frontend and adminhtml, frontend controller extending from Mage_Core_Controller_Front_Action
& adminhtml extending from Mage_Adminhtml_Controller_Action
.
前端/Adminhtml路由器可以定义为(只是一种语法):
Frontend / Adminhtml routers can be defined as (just a syntax):
<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>
您可以在以下位置创建前端控制器:app/code/[codePool]/[Namespace]/[Module]/controllers/
例如:
And you can create frontend controllers under: app/code/[codePool]/[Namespace]/[Module]/controllers/
For example:
<?php
//file: app/code/local/MagePsycho/Testmodule/controllers/IndexController.php
class MagePsycho_Testmodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction(){
}
}
为了从URL访问它:http://your-magento-url/testmodule/index/index
和adminhtml控制器在以下位置:app/code/[codePool]/[Namespace]/[Module]/controllers/Adminhtml/
例如:
In order to access it from url: http://your-magento-url/testmodule/index/index
and adminhtml controllers under:app/code/[codePool]/[Namespace]/[Module]/controllers/Adminhtml/
For example:
<?php
//file: app/code/local/MagePsycho/Testmodule/controllers/Adminhtml/IndexController.php
class MagePsycho_Testmodule_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction(){
}
}
为了从URL访问它:http://your-magento-url/testmodule/adminhtml_index/index
(您可以看到用于分隔adminhtml控制器的Adminhtml文件夹)
In order to access it from url: http://your-magento-url/testmodule/adminhtml_index/index
(You can see the Adminhtml folder for separating adminhtml controllers)
希望这会给您一些信息.
谢谢
Hope this gave you some info.
Thanks
这篇关于具有前端和管理功能的Magento模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!