views:

24

answers:

1

I have written a script (in two files) that correctly displays a Joomla user id, like this:

//this is testy.php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(FILE));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$id = JFactory::getUser()->id;

The above file is located in the Joomla root folder. The other file is in a different directory and is as follows:

//this is testid.php
include '../../joomla/testy.php';
echo $id;

However, and here is the rub, when I change the "echo" to a "return" and put the second code snippet inside my Flex 4 Data Service script file, like this...

function getUserId() {
include '../../joomla/testy.php';
return $id;
}

...I get a Flex error that says this:

Fatal error: Class 'JRequest' not found in /var/www/html/joomla/libraries/joomla/import.php on line 33

I am extremely confused by this error and would appreciate any suggestions that the stackoverflow community may have.

Thanks so much!

Zach

A: 

Based on you description and code, it looks like you are not defining JPATH_BASE correctly. This is my Joomla's functions/classes do not exist.

For example, define('JPATH_BASE', dirname(FILE)); inside your Flex file will result JPATH_BASE to equal /path/to/site/root/something/flex, but it should be just /path/to/site/rootin order to include all the libraries.

Code below is another entry point for component.
Change explode(DS."component", $path); to explode(DS."your_dir_in_root", $path);, this way your JPATH_BASE will have path to the root directory of the site.

<?php

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

// Get current file path
$path = dirname(__FILE__);

// explode the path by the directory that is in the root 
$path = explode(DS . "component", $path);

// Store path to the root directory to JPATH_BASE
define('JPATH_BASE', $path[0]);

// Include files
require_once ( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once ( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );

// Init Framework
$mainframe = & JFactory::getApplication('site');
$mainframe->initialise();

....
?>
Alex
Firstly, thanks for your quick response! However, after debugging the paths given to the function it seems those are all solid, so that's not the error. I guess it must just be something with Flex having to call a PHP function that uses another PHP function...perhaps this is a limitation in Flex?
Zachary G. Schroeder