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 Answer 1

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.

4
  • 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
    Commented Jul 7, 2014 at 5:35
  • Specifically it said "Those two includes import the framework, including JFactory, into the execution path."
    – TryHarder
    Commented Jul 7, 2014 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
    Commented Jul 7, 2014 at 21:51
  • I should have included the code when I posted. Anyway I've updated the question. Thanks.
    – TryHarder
    Commented Jul 8, 2014 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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