有没有办法使用 PHP 数据服务从 Flex 4 应用程序访问 Joomla 1.5 用户变量(如用户 ID)?

发布于 2024-09-27 17:00:22 字数 1004 浏览 5 评论 0原文

我已经编写了一个脚本(在两个文件中),可以正确显示 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 ( JPATH_BASE .DS.'includes'.DS.'framework.php' );  
$mainframe =& JFactory::getApplication('site');  
$id = JFactory::getUser()->id;

上述文件位于 Joomla 根文件夹中。另一个文件位于不同的目录中,如下所示:

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

但是,当我将“echo”更改为“return”并将第二个代码片段放入我的 Flex 4 Data Service 脚本文件中时,这就是问题所在,如下所示...

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 社区可能提供的任何建议。

非常感谢!

扎克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洒一地阳光 2024-10-04 17:00:22

你好,Rawan,

我确实找到了一个解决方案,但它有点黑客,所以我不知道你是否想使用它。

在您的 Flex 应用程序中,添加两件事。首先是一个方法,如下所示:

private function initVars():void {
   userid = FlexGlobals.topLevelApplication.parameters.id;
}

然后,将此行添加到应用程序标头:

creationComplete="initVars()"

如原始问题所示,在 Joomla 目录中包含“testy.php”文件。创建 Flex 应用程序的发布版本后,打开应用程序的包装 html 文件(位于发布版本目录中)。将此文件的扩展名更改为“.php”。然后在这个新创建的 PHP 文件中,添加以下行(注意:您可能必须更改目录移动以适合您的目录方案):

<?
include '../../joomla/testy.php';
idVar $id;
?>

在发布构建文件中,您将找到这一行:

var flashvars = {};

Flex 允许我们在我们的目录中包含外部变量应用程序。因此,在这一行的正下方添加一个新行,因此:

flashvars.id = "<?php echo $idVar; ?>";

我们现在告诉 Flex 应用程序包含一个名为“id”的 flashvar,它等于我们从 Joomla 中提取的用户 ID。

总之,您现在可以使用 Flex 变量“userid”(在我们上面编写的 Flex 方法中定义)来执行诸如从数据库中获取用户数据之类的操作。我称这个解决方案为 hackish,因为每次创建新的发布版本时,您都必须将 html 包装器更改为 php 并像我们上面所做的那样进行更改。

希望这有帮助。

干杯,

扎克

Greetings Rawan,

I did find a solution, but it's a bit hackish so I don't know if you'd want to use it.

In your Flex application, add two things. First a method, that looks like this:

private function initVars():void {
   userid = FlexGlobals.topLevelApplication.parameters.id;
}

Then, add this line to the application header:

creationComplete="initVars()"

As in the original question, include the "testy.php" file in the Joomla directory. Upon creating a release build of the Flex app, open the wrapping html file for the app (located in the release build directory). Change this file's extension to ".php". Then in this newly created PHP file, add these lines in (NOTE: you may have to change your directory movement to fit your directory scheme):

<?
include '../../joomla/testy.php';
idVar $id;
?>

In the release build file you will find this line:

var flashvars = {};

Flex allows us to include external variables in our app. So, directly below this line add a new line, thusly:

flashvars.id = "<?php echo $idVar; ?>";

We have now told our Flex app to include a flashvar with the name "id," and it's equal to the user ID we pulled from Joomla.

In conclusion, you can now use the Flex variable "userid" (defined in the Flex method we wrote above) to do things like grab user data from your database. I call this solution hackish because every time you create a new release build you must change the html wrapper to php and alter it like we did above.

Hope this helps.

Cheers,

Zach

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文