从Joomla 3.4中的另一个组件控制器调用模型 [英] Call model from another component controller in Joomla 3.4

查看:152
本文介绍了从Joomla 3.4中的另一个组件控制器调用模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Joomla 3.4 application,在这里我必须将一个组件模型调用到另一个组件控制器中,而不是从那里调用.

I am developing Joomla 3.4 application where I have to call one component model into another component controller but not call from there.

支持,我有2个组成部分

Support, i have 2 component

>> comp1
  model: m1
  controller: c1
>> comp2
  model: m2
  controller: c2

我想打comp1 model (m1) into comp2 controller (c2).

我尝试使用以下代码:

$model    = $this->getModel('m1', '', array());

但是,如果上述代码在comp1 controller (c1)中使用,则在$model中获取空值,然后运行完美.

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.

谢谢

推荐答案

这是一个老问题,但迟到总比没有好,我希望它将对其他开发人员有所帮助.

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.

这篇关于从Joomla 3.4中的另一个组件控制器调用模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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