0

I'm a beginner in joomla. I create own component and would like to use model from other component (exactly contentbuilder). I find few different ways how to create model but my problem is that

class ContentbuilderModelEdit extends JModel

use JPATH_COMPONENT_ADMINISTRATOR in it. When i create model ContentbuilderModelEdit i get warnings in lines that using JPATH_COMPONENT_ADMINISTRATOR constant.

Is it possible to create model using that constant from other component?

Thanks for your answers

cubixx
  • 11
  • 1

2 Answers2

2

Alas no. The JPATH_COMPONENT and JPATH_COMPONENT_ADMINISTRATOR are defined constants, and cannot be changed.

Sometimes the developers do this instinctively (it's easy) without realizing the kind of limitation they're putting on other developers. You might consider contacting the developers and propose such a change; if they accept, you won; if they don't, write a sed script that performs the changes (replacing it with JPATH_SITE and JPATH_ADMINISTRATOR . '/components/com_contentbuilder', and apply it after each update.

Or, copy their model into your component and rename it if it supports it.

Riccardo Zorn
  • 5,590
  • 1
  • 20
  • 36
0

:)

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.

ref link

Community
  • 1
  • 1
Sh4msi
  • 1,231
  • 13
  • 15