douxiza9868 2010-10-15 02:23
浏览 40

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

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

  • 写回答

1条回答 默认 最新

  • dongmi0760 2011-01-12 19:47
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了