0

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?

jost21
  • 1,084
  • 3
  • 15
  • 29

1 Answers1

2
  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.

Community
  • 1
  • 1
Craig
  • 9,335
  • 2
  • 34
  • 38