问题
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.
QUESTION 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)
QUESTION 2
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) Is there a way to directly access another modules models?
b) Could I extend my models between modules in a similar way to question 1 for controllers
PREVIOUS QUESTION
My CI2 app is using the wiredesigns modular layout.
I have a two modules called item and product in a a folder called modules like so:
/application
/modules
/item
/product
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
回答1:
The correct answer here is:
Don't
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.
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.
来源:https://stackoverflow.com/questions/14002626/codeigniter-class-inheritance-between-modules-wiredesigns-again