有没有办法使用PHP数据服务从Flex4应用程序访问Joomla 1.5用户变量(如用户id)?
我编写了一个脚本(在两个文件中),可以正确显示Joomla用户id,如下所示:有没有办法使用PHP数据服务从Flex4应用程序访问Joomla 1.5用户变量(如用户id)?,php,flex4,joomla1.5,dataservice,Php,Flex4,Joomla1.5,Dataservice,我编写了一个脚本(在两个文件中),可以正确显示Joomla用户id,如下所示: //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 ( JPA
//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;
private function initVars():void {
userid = FlexGlobals.topLevelApplication.parameters.id;
}
上述文件位于Joomla根文件夹中。另一个文件位于不同的目录中,如下所示:
//this is testid.php
include '../../joomla/testy.php';
echo $id;
然而,这里是难点,当我将“echo”更改为“return”并将第二个代码段放入Flex 4数据服务脚本文件中时,如下所示
function getUserId() {
include '../../joomla/testy.php';
return $id;
}
…我得到一个Flex错误,上面说:
Fatal error: Class 'JRequest' not found in /var/www/html/joomla/libraries/joomla /import.php on line 33
我对这个错误感到非常困惑,希望stackoverflow社区能提供任何建议
非常感谢
扎克问候拉万
我确实找到了一个解决方案,但它有点粗糙,所以我不知道你是否愿意使用它
在Flex应用程序中,添加两件事。首先是一个方法,如下所示:
//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;
private function initVars():void {
userid = FlexGlobals.topLevelApplication.parameters.id;
}
然后,将此行添加到应用程序标题:
creationComplete="initVars()"
与原始问题一样,在Joomla目录中包含“testy.php”文件。创建Flex应用程序的发布版本后,打开应用程序的包装html文件(位于发布版本目录中)。将此文件的扩展名更改为“.php”。然后在这个新创建的PHP文件中,添加以下行(注意:您可能需要更改目录移动以适应目录方案):
Flex允许我们在应用程序中包含外部变量。因此,在这一行的正下方添加一个新行,因此:
flashvars.id = "<?php echo $idVar; ?>";
flashvars.id=”“;
我们现在已经告诉我们的Flex应用程序包含一个名为“id”的flashvar,它等于我们从Joomla获取的用户id
总之,您现在可以使用Flex变量“userid”(在我们上面编写的Flex方法中定义)执行从数据库获取用户数据之类的操作。我称此解决方案为hackish,因为每次创建新的发布版本时,都必须将html包装更改为php,并像上面所做的那样进行更改
希望这有帮助
干杯
扎克