Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:02:34+00:00 2026-05-25T06:02:34+00:00

I am new to working with Joomla and I am adapting an external php

  • 0

I am new to working with Joomla and I am adapting an external php class I wrote for v1.5.
Without going into all the details, basically, I use a function to load the Joomla environment after which everything in Joomla is available to the class.
This is essentially done using the index.php file.

It works fine with v1.5 and has done for a while but trying to adapt it for v1.6, it falls over.

Here is the function:

    private function loadJoomla() {
        $path_base = rtrim($this->joomFullPath, '/');

        // Set flag that this is a parent file
        define( '_JEXEC', 1 );
        define( 'DS', DIRECTORY_SEPARATOR );

        switch ($joomlaVersion) {
            case 'v1.6':
                if (file_exists($path_base . '/defines.php')) {
                    include_once $path_base . '/defines.php';
                }
                if (!defined('_JDEFINES')) {
                    define('JPATH_BASE', $path_base);
                    require_once JPATH_BASE.'/includes/defines.php';
                }
                require_once JPATH_BASE.'/includes/framework.php';

                // Mark afterLoad in the profiler.
                JDEBUG ? $_PROFILER->mark('afterLoad') : null;

                // Instantiate the application.
                $app = JFactory::getApplication('site');

                // Initialise the application.
                $app->initialise();

                // Mark afterIntialise in the profiler.
                JDEBUG ? $_PROFILER->mark('afterInitialise') : null;

                // Route the application.
                $app->route();

                // Mark afterRoute in the profiler.
                JDEBUG ? $_PROFILER->mark('afterRoute') : null;

                // Dispatch the application.
                $app->dispatch();

                // Mark afterDispatch in the profiler.
                JDEBUG ? $_PROFILER->mark('afterDispatch') : null;

                // Render the application.
                $app->render();

                // Mark afterRender in the profiler.
                JDEBUG ? $_PROFILER->mark('afterRender') : null;

                // Return the response.
                return $app;
            break;
            case 'v1.5':
                // PREPARE
                define('JPATH_BASE', $path_base);
                require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
                require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
                JDEBUG ? $_PROFILER->mark( 'afterLoad' ) : NULL;

                // CREATE THE APPLICATION
                $GLOBALS['mainframe'] =& JFactory::getApplication('site');

                // INITIALISE THE APPLICATION
                /* set the language */
                $GLOBALS['mainframe']->initialise();
                JPluginHelper::importPlugin('system');
                /* trigger the onAfterInitialise events */
                JDEBUG ? $_PROFILER->mark('afterInitialise') : NULL;
                $GLOBALS['mainframe']->triggerEvent('onAfterInitialise');

                // ROUTE THE APPLICATION
                $GLOBALS['mainframe']->route();
                /* authorization */
                $GLOBALS['Itemid'] = JRequest::getInt( 'Itemid');
                $GLOBALS['mainframe']->authorize($GLOBALS['Itemid']);
                /* trigger the onAfterRoute events */
                JDEBUG ? $_PROFILER->mark('afterRoute') : NULL;
                $GLOBALS['mainframe']->triggerEvent('onAfterRoute');

                // DISPATCH THE APPLICATION
                $GLOBALS['option'] = JRequest::getCmd('option');
                $GLOBALS['mainframe']->dispatch($GLOBALS['option']);
                /* trigger the onAfterDispatch events */
                JDEBUG ? $_PROFILER->mark('afterDispatch') : NULL;
                $GLOBALS['mainframe']->triggerEvent('onAfterDispatch');

                // RENDER  THE APPLICATION
                $GLOBALS['mainframe']->render();
                /* trigger the onAfterRender events */
                JDEBUG ? $_PROFILER->mark('afterRender') : NULL;
                $GLOBALS['mainframe']->triggerEvent('onAfterRender');

                // RETURN THE RESPONSE
                return JResponse::toString($GLOBALS['mainframe']->getCfg('gzip'));
            break;
            default:
                return NULL;
            break;
        }

As said, the v1.5 bit works fine and is just the index.php file with the mainframe variable made global. The v1.6 bit falls over at ‘$app->dispatch();’.

Debugging the flow using ‘die’ took me to function dispatch in /libraries/joomla/application.php where I found that the fall over point was ‘$contents = JComponentHelper::renderComponent($component);’ which took me to function renderComponent in /libraries/joomla/application/component/helper.php

A few ‘dies’ later, I found the fall over point to be, wait for it, ‘ob_start();’.
Completely baffled especially since checking in v1.5 code, I can see it is exactly the same as v1.6 here.

I suspect the $app scope may be the reason behind this and will appreciate some help. I tried the obvious “$GLOBALS[‘app’]” with no joy.

Thanks for taking the time and pointers appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:02:35+00:00Added an answer on May 25, 2026 at 6:02 am

    I managed to solve this problem as follows.

    There were two separate issues happening.

    Firstly, The v1.6 section did not have the “$option” parameter properly initialised. Thanks to user hbit in this query I made, I was able to solve that. by changing the code as follows:

    // Dispatch the application.
    $option = JRequest::getCmd('option');
    $app->dispatch($option);
    

    However, that did not solve the issue and the code was still crashing at the ‘ob_start’ point.

    Secondly, I couldn’t get to the actual reason for the crash but went for a workaround. Since the ob_start bit in question, located in /libraries/joomla/application/component/helper.php, is only there to gather a component output into a variable, I worked around it by pulling the code that ‘$app->dispatch($option)’ fires into my file and amended the problem section.

    First, I modified the main section as follows:

    // Dispatch the application.
    $option = JRequest::getCmd('option');
    /** The process crashes here for some reason 
    * (See https://stackoverflow.com/questions/7039162/).
    * So we comment out the Joomla! function, pull the code in here and 
    * push the component content into the Joomla document buffer ourselves.
    **/
    //$app->dispatch($option);
    $this->joomdispatch($option);
    

    I then wrote a ‘joomdispatch’ function as follows:

    private function joomdispatch($option) {
        /************************
         * This is pulled from function 'render' 
         * in /libraries/joomla/application.php
         ************************/
        $document = JFactory::getDocument();
        $document->setTitle(JApplication::getCfg('sitename'). ' - ' .JText::_('JADMINISTRATION'));
        $document->setDescription(JApplication::getCfg('MetaDesc'));
    
        /************************
         * This is pulled from function 'renderComponent' 
         * in /libraries/joomla/application/component/helper.php
         * Function 'renderComponent' is called by the
         * '$contents = JComponentHelper::renderComponent($component);' line
         * We exclude that line and jump to the function code
         ************************/
    
        // Initialise variables.
        $app = JFactory::getApplication();
    
        // Load template language files.
        $template   = $app->getTemplate(true)->template;
        $lang = JFactory::getLanguage();
        $lang->load('tpl_'.$template, JPATH_BASE, null, false, false)
            ||  $lang->load('tpl_'.$template, JPATH_THEMES."/$template", null, false, false)
            ||  $lang->load('tpl_'.$template, JPATH_BASE, $lang->getDefault(), false, false)
            ||  $lang->load('tpl_'.$template, JPATH_THEMES."/$template", $lang->getDefault(), false, false);
    
        $scope = $app->scope; //record the scope
        $app->scope = $option;  //set scope to component name
    
        // Build the component path.
        $option = preg_replace('/[^A-Z0-9_\.-]/i', '', $option);
        $file   = substr($option, 4);
    
        // Define component path.
        define('JPATH_COMPONENT',               JPATH_BASE.DS.'components'.DS.$option);
        define('JPATH_COMPONENT_SITE',          JPATH_SITE.DS.'components'.DS.$option);
        define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR.DS.'components'.DS.$option);
    
        // get component path
        if ($app->isAdmin() && file_exists(JPATH_COMPONENT.DS.'admin.'.$file.'.php')) {
            $path = JPATH_COMPONENT.DS.'admin.'.$file.'.php';
        } else {
            $path = JPATH_COMPONENT.DS.$file.'.php';
        }
    
        $task = JRequest::getString('task');
    
        // Load common and local language files.
        $lang->load($option, JPATH_BASE, null, false, false)
            ||  $lang->load($option, JPATH_COMPONENT, null, false, false)
            ||  $lang->load($option, JPATH_BASE, $lang->getDefault(), false, false)
            ||  $lang->load($option, JPATH_COMPONENT, $lang->getDefault(), false, false);
    
        // Handle template preview outlining.
        $contents = null;
    
        // Get component html
        /************************
         * This has been edited from the native 'ob_start'.
         * Could use curl as well
          ***********************/
        $contents = file_get_contents($this->joomUrl . '/index.php?' . $this->joomQS);
    
        // Build the component toolbar
        jimport('joomla.application.helper');
    
        if (($path = JApplicationHelper::getPath('toolbar')) && $app->isAdmin()) {
            // Get the task again, in case it has changed
            $task = JRequest::getString('task');
    
            // Make the toolbar
            include_once $path;
        }
    
        $app->scope = $scope; //revert the scope
    
        /************************
         * Back to function 'renderComponent' code
         * to complete process
         ************************/
        $document->setBuffer($contents, 'component');
    
        // Trigger the onAfterDispatch event.
        JPluginHelper::importPlugin('system');
        JApplication::triggerEvent('onAfterDispatch');
    }
    

    With this, everything works fine. Didn’t get to the bottom of the (strange) error but managed to get around it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed new site in Joomla 1.7 and its working fine, but when
So, I've just started working with a new Joomla site, and something we've added
I am working on a joomla website but as I am new to joomla
I am working on a new project and I am using Joomla version 1.5.22.
New to working with Visual Studio Solutions. I normally place my Site Class file
I'm working with a CMS, Joomla, and there's a core class which renders a
I am working on redirecting all files in the URI(?) www.gdlsk.com/practice to this new
I am really new to Joomla and Virtue Mart and have inherited a working
Im new to working with Domain Models so forgive me for asking an elementary
I'm rather new to working with multiple threads in a database (most of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.