问题描述
我尝试使用 getUser() 函数和位于 Joomla 的 iframe(包装器)中的 php 脚本获取我的用户信息.将参数传递给 iframe 代码似乎存在问题.我能捕获用户信息的唯一方法是将代码插入到基本文章(不是 iframe)中.
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 iframe code. The only way I can catch user informations is to insert the code into a basic article (which is not an iframe).
var_dump($user);输出显示:
The var_dump($user); output shows :
object(JUser)#17 (23) { ["isRoot":protected]=> NULL ["id"]=> int(0) ["name"]=> NULL ["username"]=> NULL ["email"]=> NULL ["password"]=> NULL ["password_clear"]=> string(0) "" ["usertype"]=> NULL ["block"]=> NULL ["sendEmail"]=> int(0) ["registerDate"]=> NULL ["lastvisitDate"]=> NULL ["activation"]=> NULL ["params"]=> NULL ["groups"]=> array(0) { } ["guest"]=> int(1) ["_params":protected]=> object(JRegistry)#18 (1) { ["data":protected]=> object(stdClass)#19 (0) { } } ["_authGroups":protected]=> NULL ["_authLevels":protected]=> NULL ["_authActions":protected]=> NULL ["_errorMsg":protected]=> NULL ["_errors":protected]=> array(0) { } ["aid"]=> int(0) }
知道出了什么问题吗?谢谢,佛罗伦
Some idea of what is going wrong ? Thank you, Florent
<?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' );
$user = JFactory::getUser();
echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is $user->username}</p>";
echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>";
//var_dump($user);
?>
推荐答案
如前所述,如果您使用包装器,Joomla 环境是未知的.所以你需要在使用 Joomla API 之前嵌入它.为此,只需复制并粘贴此代码(或创建一个新的 PHP 文件并将其包含在您的自定义页面中):
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();
?>
这篇关于如何将 Joomla 参数传递给 iframe(包装器)页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!