How can I access global SugarCRM variables from a custom javascript file that I have attached to a field on the DetailView
in SugarCRM V6.5.
如何从我附加到SugarCRM V6.5的DetailView字段的自定义javascript文件中访问全局SugarCRM变量。
Specifically, I want to access the $current_user
global PHP variable from the Javascript file.
具体来说,我想从Javascript文件访问$current_user全局PHP变量。
I have added the javascript file by editing the custom/modules/Accounts/views/detailviewdef.php
and then editing the array to look like this
我通过编辑自定义/模块/帐户/视图/detailviewdef添加了javascript文件。然后编辑数组,使其看起来像这样
array ( 0 =>
array (
'file' => 'modules/Accounts/Account.js',
),
1 =>
array (
'file' => 'custom/modules/Accounts/Account1.js',
),
),
The details that i want to access from the $current_user
is actually a customization that I made to the User
module to add more configuration option for every user.
我想从$current_user访问的细节实际上是我为User模块定制的,以便为每个用户添加更多配置选项。
I saw somewhere else on Google that i could use var current_user = current_user;
in the custom Javascript file and it actually shows the user ID of the logged in user, however what i really want is to get the User detail Object, please does anyone have any ideas.
我在谷歌上看到可以使用var current_user = current_user;在自定义Javascript文件中,它实际上显示了登录用户的用户ID,但是我真正想要的是获取用户细节对象,请大家有什么想法。
Regards
问候
1 个解决方案
#1
0
I would suggest to write a controller that send back the whole current_user data in json.
我建议编写一个控制器,以json格式发送回整个current_user数据。
custom/modules/Accounts/controller.php
自定义/模块/账户/ controller.php
class AccountsController extends SugarController{
function __construct(){
parent::__construct();
}
function action_getCurrentUser(){
echo json_encode($GLOBALS['current_user']);
}
}
And in your js file call it like this:
在你的js文件中这样称呼它:
var request = $.ajax({
url: 'index.php',
data: {
module: 'Accounts',
action: 'getCurrentUser',
to_pdf: true, // this reduces the response so that json works
},
#1
0
I would suggest to write a controller that send back the whole current_user data in json.
我建议编写一个控制器,以json格式发送回整个current_user数据。
custom/modules/Accounts/controller.php
自定义/模块/账户/ controller.php
class AccountsController extends SugarController{
function __construct(){
parent::__construct();
}
function action_getCurrentUser(){
echo json_encode($GLOBALS['current_user']);
}
}
And in your js file call it like this:
在你的js文件中这样称呼它:
var request = $.ajax({
url: 'index.php',
data: {
module: 'Accounts',
action: 'getCurrentUser',
to_pdf: true, // this reduces the response so that json works
},