0

我运行一个基于 Joomla 的站点,我试图让对讲机通过 php 提取登录的用户数据。有谁知道这些行的正确公式是什么(或者我在哪里可以找到它?):

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

第二个问题:没有登录用户会怎样?

仅供参考:不幸的是,我不是 php 流利的!

完整代码:

<script>
  window.intercomSettings = {
    app_id: "*****",
    name: "<?php echo $current_user->name ?>", // Full name
    email: "<?php echo $current_user->email ?>", // Email address
    created_at: <?php echo strtotime($current_user->created_at) ?> // Signup date as a Unix timestamp
  };
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/unvfagbb';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
4

2 回答 2

0

您不能直接将数据从 Joomla 拉到 Intercom,您需要调用 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)ETC

于 2017-02-05T05:18:48.083 回答
0

获取用户对象:(将此行放在 <script> 标记之前)

$current_user = JFactory::getUser();

另见:https ://docs.joomla.org/Accessing_the_current_user_object

于 2017-02-04T23:13:22.560 回答