Sometimes you may wish to reuse a certain function that resides in a model outside of your current scope. This helps you save time and reduce duplication. This can be achieved easily by adding the following codes.
Assuming you are trying to call a model "Categories" (/components/com_mycomponent/models/categories.php) belonging to com_mycomponent (this can be called from either within or outside of the com_mycomponent):
jimport('joomla.application.component.model'); JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_mycomponent/models'); $categoriesModel = JModelLegacy::getInstance( 'Categories', 'MyComponentModel' );
Now you can call its methods, example:
$categoriesModel->getCategories();