具有前端和管理功能的 Magento 模块 [英] Magento Module with Frontend and Admin functionality

查看:24
本文介绍了具有前端和管理功能的 Magento 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为 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.

不过,我现在正在转向管理方面的工作.但是,我对如何将管理部分添加到路由器并让它调用相关控制器感到有些困惑.

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.

推荐答案

根据区域(frontend 或 adminhtml),调度 frontend 或 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.

Frontend/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 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆