How to pass Joomla parameters to an iframe (wrapper) page?

后端 未结 2 1720
情歌与酒
情歌与酒 2021-01-27 06:14

I try to fetch my users information using the getUser() function with a php script located in a iframe (wrapper) of Joomla. It seems there is problem passing parameters to ifram

相关标签:
2条回答
  • 2021-01-27 06:52

    As previously said, wchen you use a wrapper, the Joomla environment is unknown. So you need to embed this before using Joomla API. To do this, just copy and paste this code (or create a new PHP file and include it in your custom page) :

    <?php
    define('_JEXEC', 1 );
    define('JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] ); 
    define( 'DS','/' );
    
    require_once ( JPATH_BASE.DS. 'includes'.DS.'defines.php' );
    require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php' );
    require(JPATH_BASE.DS.'libraries/joomla/factory.php');
    
    $mainframe =& JFactory::getApplication('site');
    $mainframe->initialise();
    ?>
    
    0 讨论(0)
  • 2021-01-27 07:00

    Of course, the page that includes the iframe doesn't "know" Joomla - it's a different environment!

    If I understood correctly what you're trying to achieve, then you really should create an article in Joomla that displays the user information, but instead of getting the user-id from:

    $user = JFactory::getUser();
    

    you should send it as POST/GET parameter from the OUTER page (you can add some kind of auth-string if security matters to you). The article will read this POST/GET parameter and display the user's information respectively.

    The OUTER page (the one that contains the iframe) should refresh the iframe and use, as a url, the same url that displays the article (make sure it has "public" permissions) but will also send the user-id as parameter, for example:

    iframe src="http://<url to joomla>?id=articleId&userId=<user-id>
    

    hope it helps!

    0 讨论(0)
提交回复
热议问题