问题
I am developing Joomla 3.4 application
where I have to call one component model into another component controller but not call from there.
Support, i have 2 component
>> comp1
model: m1
controller: c1
>> comp2
model: m2
controller: c2
I want to call comp1 model (m1) into comp2 controller (c2).
I tried using below code:
$model = $this->getModel('m1', '', array());
But in $model
get null value if above code use in comp1 controller (c1)
then run perfect.
What actually issue is not getting. Any one have a perfect idea.
Thanks
回答1:
This is an old question but better late than never and I hope it will help other developers.
To call a model from another component you need firstly to include the path of this model:
JModelLegacy::addIncludePath(JPATH_SITE . '/components/comp1/models', 'Comp1Model');
Secondly you have to create an instance of your model:
$model = JModelLegacy::getInstance('Model1', 'Comp1Model');
After that you should be able to use the methods of your model.
来源:https://stackoverflow.com/questions/30024597/call-model-from-another-component-controller-in-joomla-3-4