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' );
$categoriesModel->getCategories();
<?php
JLoader::import('joomla.application.component.model');
// file name, full path
JLoader::import( 'product', JPATH_ADMINISTRATOR . DS . 'components' .
DS . 'com_virtuemart' . DS . 'models' );
$productModel = JModel::getInstance( 'Product', 'VirtueMartModel' );
?>
No comments:
Post a Comment