7

I am migrating my Joomla 2.5 site to Joomla 3.3.

Now I'm struggling with loading the joomla framework and displaying a module in a phpbb-Template. Loading the Joomla framework worked fine in Joomla 2.5 with this code:

define( '_JEXEC', 1 );
define('JPATH_BASE', '/var/customers/webs/tf2swiss/joomlasite');
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
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' );
require( JPATH_LIBRARIES. '/import.php');
// Joomla! library imports
jimport( 'joomla.environment.uri' );
jimport( 'joomla.user.user');
jimport('joomla.application.module.helper');

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');

But I doesn't work in Joomla 3.x now. The page stopps loading where this code is. Using PHP in phpbb template files is enabled in the Security options.

Does anyone know how to load the joomla 3.x framework in external files?

Oddy
  • 142
  • 1
  • 1
  • 11
  • If anybody finds this actually looking for how to load Joomla 1.5 (yes, used even in 2017, especially with virtuemart) ... : https://docs.joomla.org/Initializing_the_Joomla!_1.5_Framework_in_an_external_script – jave.web Jan 10 '17 at 14:49

1 Answers1

13

The following works perfectly for me:

define('_JEXEC', 1);
define('JPATH_BASE', '../');
require_once JPATH_BASE . 'includes/defines.php';
require_once JPATH_BASE . 'includes/framework.php';

// Create the Application
$app = JFactory::getApplication('site');

Try changing this line which you currently have to a relative path as shown above. You may been to change ../ according to where you have your Joomla root in relation to your external file.

define('JPATH_BASE', '/var/customers/webs/tf2swiss/joomlasite');

To test if it's working, simply use something like this:

var_dump($app);

If you see data being shown, then your have successfully imported the framework

jave.web
  • 13,880
  • 12
  • 91
  • 125
Lodder
  • 19,758
  • 10
  • 59
  • 100
  • Thanks for the reply. This works in a php-file, but does not work in my phpBB template overall_header.html. The site stopps loading at `$app = JFactory::getApplication('site')` – Oddy May 29 '14 at 18:26
  • Nevermind, phpBB is very annoying sometimes. It seems to work when I include this code as an external php file ``. Thanks anyway – Oddy May 29 '14 at 18:41
  • 1
    I used this - define('JPATH_BASE', realpath(dirname(__FILE__))); instead of define('JPATH_BASE', '../'); – cha Feb 20 '15 at 12:49