Category Archives: Joomla

Call or load any Joomla model to controller, other modules or plugin

Here’s a short version:

first, load model helper


second, import the model, adjust with your own component, first parameter is the filename without .php

JLoader::import( 'renewal', JPATH_ROOT . DS . 'components' . DS . 'com_mymember' . DS . 'models' );

third, create new instance. in this case, the class name is mcsmemberModelRenewal

$renewalmodel = JModel::getInstance( 'renewal', 'mcsmemberModel' );

now you can use the model, ie:


happy coding!

Include Joomla core functionality in external PHP file

Once I need to have Joomla core class in external files, answer can be found here. To repeat myself, here’s minimum code required to have Joomla functionality in our own file.

//define constant
define( '_JEXEC', 1 );
//you need to adjust joomla path according to your joomla installation
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] . DS . 'joomla' );
//include joomla core files
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );
//create application
$mainframe =& JFactory::getApplication('site');
//in this point, you're ready to use joomla functionality
//example: initialize database object
$db = JFactory::getDBO();
//or import plugin helper
//to test whether some plugins is enabled
$pluginenabled = &JPluginHelper::isEnabled('authentication', 'joomla');

Happy coding!