Standalone Joomla! application - JRoute problem

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
evilmint
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed Apr 02, 2014 7:18 pm

Standalone Joomla! application - JRoute problem

Post by evilmint » Thu Nov 27, 2014 10:16 am

Hello, I'm creating a standalone script beside 'index.php' which purpose is to connect to the database, prepare some data, and which is the most important part - use JRoute.

The biggest problem, however, is that when using JRoute, a bug comes out.

Code: Select all

Error displaying the error page: Application Instantiation Error: Application Instantiation Error
The code I used for initalizing the Joomla framework is as follows:

Code: Select all

define('_JEXEC', 1); 
		define('JPATH_BASE', realpath(dirname(__FILE__).'/')); // print this out or observe errors to see which directory you should be in (this is two subfolders in) 
		define('DS', DIRECTORY_SEPARATOR); 


		require_once (JPATH_BASE.DS.'includes'.DS.'defines.php'); 
		require_once (JPATH_BASE.DS.'includes'.DS.'framework.php'); 
		require_once (JPATH_BASE.DS.'configuration.php'); 
		require_once (JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'database'.DS.'database.php'); 
		require_once (JPATH_BASE.DS.'libraries'.DS.'import.php'); 
		
		global $config;
		
		$config = new JConfig(); 
		
		$db_driver      = $config->dbtype;   // Database driver name 
		$db_host        = $config->host;     // Database host name 
		$db_user        = $config->user;     // User for database authentication 
		$db_pass        = $config->password; // Password for database authentication 
		$db_name        = $config->db;       // Database name 
		$db_prefix      = $config->dbprefix; // Database prefix (may be empty)
Code used to call JRoute:

Code: Select all

JRoute::_('index.php?option=com_content&view=article&id='.$item->id);
What am I missing?

jcms
I've been banned!
Posts: 2233
Joined: Wed Nov 19, 2014 9:23 am

Re: Standalone Joomla! application - JRoute problem

Post by jcms » Sat Nov 29, 2014 5:13 pm

try this to embed joomla
<?php
define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require( JPATH_LIBRARIES .DS.'joomla'.DS.'import.php');

jimport( 'joomla.environment.uri' );
jimport( 'joomla.user.user');
jimport('joomla.application.module.helper');

$mainframe = JFactory::getApplication('site');

?>

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: Standalone Joomla! application - JRoute problem

Post by sovainfo » Sat Nov 29, 2014 8:58 pm

Have a look at the scripts in cli, they provide a more recent version than you are using and what is suggested by @jcms.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!

evilmint
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed Apr 02, 2014 7:18 pm

Re: Standalone Joomla! application - JRoute problem

Post by evilmint » Sun Nov 30, 2014 6:26 pm

Thanks a lot @sovainfo, that was very helpful of you. Everything now works as intended :)


Locked

Return to “Joomla! 3.x Coding”