title: bootstrapping joomla 2.5 from an external script
body: <p>This used to work in 1.5... I could set up the following code:</p>
  
  <pre><code>function startJoomla() {
      define('_JEXEC', true);
      define( 'DS', DIRECTORY_SEPARATOR );
      $dir= dirname(__FILE__);
      define('JPATH_BASE', $dir);
      // load joomla libraries
      require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
      require_once JPATH_LIBRARIES . DS . 'loader.php';
      jimport('joomla.base.object');
      jimport('joomla.factory');
      jimport('joomla.filter.filterinput');
      jimport('joomla.error.error');
      jimport('joomla.event.dispatcher');
      jimport('joomla.event.plugin');
      jimport('joomla.plugin.helper');
      jimport( 'joomla.utilities.utility' );
      jimport('joomla.utilities.arrayhelper');
      jimport('joomla.environment.uri');
      jimport('joomla.environment.request');
      jimport('joomla.user.user');
      // JText cannot be loaded with jimport since it's not in a file called text.php but in methods
      JLoader::register('JText', JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'methods.php');
      JLoader::register('JRoute', JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'methods.php');
  
      $mainframe = &amp; JFactory::getApplication('site');
      $GLOBALS['mainframe'] = &amp; $mainframe;
      return $mainframe;
      }
  
  $mainframe = startJoomla();
  
  jimport('joomla.filesystem.folder');
  jimport('joomla.filesystem.file');
  </code></pre>
  
  <p>And then, when I wanted to call something up from Joomla, I could do the following:</p>
  
  <pre><code>$custom = new CustomController(); // assuming there's a com_custom somewhere
  </code></pre>
  
  <p>This worked for 1.5.  But in 2.5, the above doesn't work at all.  I found a revised version of the load script:</p>
  
  <pre><code>function startJoomla() {
      define('_JEXEC', 1);
      define( 'DS', DIRECTORY_SEPARATOR );
      $dir = dirname(__FILE__);
      define('JPATH_BASE', $dir); 
      // load joomla libraries
      require_once JPATH_BASE.'/includes/defines.php';
      require_once JPATH_BASE.'/includes/framework.php';
      require_once JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php';
      // Instantiate the application.
      $app = JFactory::getApplication('site');
      // Initialise the application.
      return $app-&gt;initialise();          
  }
  $mainframe = startJoomla();
  </code></pre>
  
  <p>This enables things like 'JFactory::getUser();' but will no longer allow me to utilize commands like 'new MycustomcomponentController();'  Gives me 'core' Joomla functionality, but skips everything I installed.  Is there an appropriate new revised compilation of jimport instructions or perhaps a different function of JComponent that allows me to call up my custom functions along with other components and models for use in external php files?  Assume this will be run from a CRON or similar.</p>