1

I've been reading up on how to access Joomla from external php scripts and I've noticed that there tends to be 2 flavours of code- external scripts that use require('libraries/joomla/factory.php'); and those that don't.

factory.php doesn't seem to be necessary, so for what reason(s) would you include it?

EDIT Here is an example of code that uses factory.php

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' );
1

It will depend on whether you use any JFactory:: calls, given that it provides useful functions like:

getApplication
getConfig
getSession
getLanguage
getDocument
getUser
getCache
getACL
getDbo
getMailer
getFeedParser
getXML
getEditor
getURI
getDate
createConfig
createSession
createDbo
createMailer
createLanguage
createDocument
getStream

I can imagine a lot of good reason to use it.

  • I read that if you include require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); and require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); JFactory would be included. Is this wrong? Link forum.joomla.org/viewtopic.php?p=1701888 – TryHarder Jul 7 '14 at 5:35
  • Specifically it said "Those two includes import the framework, including JFactory, into the execution path." – TryHarder Jul 7 '14 at 5:40
  • 1
    Well defines just setups up all the JPATH_* globals and framework is effectively the whole CMS so no then you wouldn't need JFactory to be included separately. – Craig Jul 7 '14 at 21:51
  • I should have included the code when I posted. Anyway I've updated the question. Thanks. – TryHarder Jul 8 '14 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.