如何从自定义javascript文件访问全局SugarCRM变量,该文件已附加到SugarCRM V6.5中DetailView
上的字段。
具体来说,我想从Javascript文件访问$current_user
全局PHP变量。
我通过编辑custom/modules/Accounts/views/detailviewdef.php
添加了javascript文件,然后编辑数组使其看起来像
array ( 0 =>
array (
'file' => 'modules/Accounts/Account.js',
),
1 =>
array (
'file' => 'custom/modules/Accounts/Account1.js',
),
),
我想从$current_user
访问的细节实际上是我对User
模块进行的定制,为每个用户添加更多的配置选项。
我在谷歌上的其他地方看到,我可以在自定义Javascript文件中使用var current_user = current_user;
,它实际上显示了登录用户的用户ID,但我真正想要的是获得用户详细信息对象,请有人有任何想法吗。
问候
我建议写一个控制器,用json发送回整个current_user数据。
custom/modules/Accounts/controller.php
class AccountsController extends SugarController{
function __construct(){
parent::__construct();
}
function action_getCurrentUser(){
echo json_encode($GLOBALS['current_user']);
}
}
在你的js文件中,这样称呼它:
var request = $.ajax({
url: 'index.php',
data: {
module: 'Accounts',
action: 'getCurrentUser',
to_pdf: true, // this reduces the response so that json works
},