模块之间的Codeigniter类继承(wiredesigns)-再次 [英] Codeigniter Class Inheritance between modules (wiredesigns) - again

查看:73
本文介绍了模块之间的Codeigniter类继承(wiredesigns)-再次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前曾问过这个问题:模块之间的Codeigniter类继承(wiredesigns )

I asked this question previously : Codeigniter Class Inheritance between modules (wiredesigns)

我接受了该问题的答案,该问题通过扩展应用程序/核心中的自定义控制器提供了一种实现我想要的方式的方法.这种方法似乎很明智,并提供了允许两个模块独立运行的额外好处.

I accepted an answer to that question which provided a way of doing what I want by extending a custom controller in application/core. This approach seemed sensible and offered the added benefit of allowing both modules to function independently.

但是,考虑到这一点,我不确定这是否是这种情况的最佳方法,因为我的产品"控制器将需要项目控制器的几乎所有功能,因此这种方法将使我的项目控制器几乎为空-我是我不确定我喜欢这个.

However, Having thought about it, I am not sure this is the best approach for this situation because My Products controller will require almost all of the functionality of the item controller so this approach will leave my item controller almost empty - I'm not sure I like this.

问题1

尽管我仍然可以使用先前建议的方法,但我想知道是否存在一种在模块之间扩展类的方法,以便我可以权衡这两个选项(请参见下面的原始问题)

Although I may still go with the approach previously suggested, I would like to know if there is a way to extend classes between modules so that I can weigh up the two options (see original question below)

问题2

此外,我认为我应该能够重用我的模型类的大部分内容,我可以使用app/core方法中的MY_Model来做到这一点.但是...

Additionally, I think I should be able to re-use much of my model class, I can see that I would be able to do this using the MY_Model in app/core approach. But...

a)是否可以直接访问其他模块模型?

a) Is there a way to directly access another modules models?

b)我可以用类似于问题1的控制器的方式在模块之间扩展我的模型

b) Could I extend my models between modules in a similar way to question 1 for controllers

上一个问题

我的CI2应用正在使用wiredesigns模块化布局.

My CI2 app is using the wiredesigns modular layout.

在一个名为modules的文件夹中,我有两个名为item和product的模块,如下所示:

I have a two modules called item and product in a a folder called modules like so:

/application
    /modules
        /item
        /product

在Item中,有一个名为item的控制器,其启动方式如下.

In Item I have a controller called item which starts like this.

class Item extends MX_Controller
{
    //code here
}

要使我的产品控制器在其他模块中扩展我的项目控制器,我需要做什么

What do I need to do to make my products controller extend my item controller in a different module

推荐答案

正确的答案是:

不要

您为什么要尝试这样做?将您的逻辑放入库或某种共享文件中,然后实现对该库的调用.

Why are you trying to do this? Place your logic into a library or some sort of shared file and implement a call to that library instead.

您可以在application/libraries文件夹中将Item作为抽象类,并且HMVC中内置的自动加载器将自动加载它.完全没有必要将其放在模块中,并且绝对不需要成为控制器.

You could make Item an abstract class in your application/libraries folder and the autoloader built into HMVC will automatically load it. There is no reason this needs to be in a module, and it definitely doesn't need to be a controller.

这篇关于模块之间的Codeigniter类继承(wiredesigns)-再次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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