Thursday, June 9, 2011

Include an external file in Joomla?

you need to add an external file beside joomla file system in a module and component. In this case, your external file can't use the joomla libraries easily. Following is the way to use the external file.
Add following 10 lines of code on top of your external file.

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
/* If you need to use database object, add following line too */
$db=JFactory::getDBO(); // use this $db object for database related operation

Now, use this file as normal joomla file. You can include the joomla libraries files as per the requirement also.

No comments:

Post a Comment