Call model from another component controller in Joomla 3.4

谁都会走 提交于 2020-01-17 01:40:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!