How to access Joomla 2.5 core functions from an external PHP file?

Tuesday, November 27, 2012


Create a PHP file on the root of Joomla 2.5.x

Include this script at the very beginning of the PHP file, below the PHP opening tag

<?php

// Script to access Joomla core functionality start


define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(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();

// script end

Now you can use Joomla core functionality below

For eg)

// Query to get all the datas from users table.

$db = &JFactory::getDBO();

$sql = "SELECT * FROM #__users";
$db->setQuery($sql);
$users = $db->loadObjectList();

print_r($users);

?>

You Might Also Like

0 comments