jost21
jost21

Reputation: 1376

Access Joomla from external php-script

I wrote a component for Joomla 2.5 which uses jquery in the admin part. The js-script calles a helper php file (addrow.php), which returnes a new row for a table using Joomla's form fields. Because that file is outside of the Joomla framework I used these lines to make it work:

define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../..' )); 

require_once( JPATH_BASE.'includes/defines.php' );
require_once( JPATH_BASE.'includes/framework.php' );
require_once( JPATH_BASE.'libraries/joomla/factory.php' );

After the upgrade to Joomla 3.2, this didn't work anymore, I just got

Error displaying the error page: Application Instantiation Error

but by adding

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

it works again.

My question is, if this is in general the proper way to write external php-scripts for jquery?
And is getApplication('site') correct even if it's for admin?

Upvotes: 0

Views: 829

Answers (1)

Craig
Craig

Reputation: 9330

  1. No — read this answer and this on "Using Joomla Ajax Interface"

  2. Yes, it's an acceptable form (although JFactory::getApplication() will default to the current entry point i.e. site or administrator.

Upvotes: 2

Related Questions