PHP返回登录用户

时间:2017-02-04 23:06:46

标签: php joomla intercom

我运行基于Joomla的网站,我正在尝试通过php获取对讲机来提取登录的用户数据。有谁知道这些线的正确公式是什么(或者我能找到它的地方?):

let
    Source = #table(type table[ID=Int64.Type, Date=date], {
    {501,"01/01/2017"},
    {203,"08/06/2015"},
    {304,"01/04/2014"},
    {501,"01/01/2016"},
    {201,"01/02/2015"},
    {501,"01/08/2015"}
    }),
    Convert = Table.TransformColumnTypes(Source,{{"Date", type date}}),

    AddMinDateColumn = Table.AddColumn(Convert, "Earliest Date", (thisrow) => List.Min(Table.SelectRows(Convert, each [ID] = thisrow[ID])[Date]), type date)
in
    AddMinDateColumn

第二个问题:如果没有登录用户会发生什么?

仅供参考:遗憾的是,我的PHP不流利!

完整代码:

<?php echo $current_user->name ?>
<?php echo $current_user->email ?>

2 个答案:

答案 0 :(得分:0)

获取用户对象:(将此行放在&lt; script&gt;标记之前)

$current_user = JFactory::getUser();

另见:table2struct

答案 1 :(得分:0)

您不能直接将数据从Joomla拉到内部通信,您需要调用joomla框架并访问用户属性。首先,您需要使用此代码连接到Joomla

<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', "C:\Vertrigo\www\joomla" );// Your Joomla Installation folder
//Next call the mandatory framework files
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//Initialise the mainframe
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
//get user details
$user = JFactory::getUser();
//To get current logged in user
$current_user->name = $user->username;
$current_user->email =$user->email;

如果您没有任何已登录的用户,则会获得userid = 0或guest,因此您可以使用if else语句更改代码。 if($user->id ==0)