Reputation: 11
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
Upvotes: 0
Views: 268
Reputation: 1551
:)
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.
Upvotes: 0
Reputation: 5615
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.
Upvotes: 2