SugarCRM:PHP 未在自定义按钮上从 ajax 执行
SugarCRM: PHP not being executed from ajax on custom button
我在自定义按钮上的 ajax 调用时遇到了一些问题。自定义按钮位于案例列表视图中,列表中的每个案例都有一个。单击时,此按钮应执行对自定义端点的 ajax 调用,将 assigned_user_id 更新为当前登录的用户,并重定向到与按钮关联的案例。
目前,我正在访问端点,并且可以记录通过 ajax 调用发送的案例 ID,但无法获得更新案例分配用户的调用。
这是 ajax 调用:
function take_ticket(url, id) {
$.ajax({
url: '/custom/modules/Cases/assign_ticket.php',
contentType: 'JSON',
data: {
'id': id
},
success: function(response){
window.location = url;
//alert(response);
},
error: function(response) {
alert('Error');
}
});
return false;
}
这是我创建的自定义端点(请注意,我正在对用户 ID 进行硬编码以进行测试):
<?php
if ($_GET['id']) {
$test = $_GET['id'];
updateUser($test);
}
function updateUser($test) {
$case = new aCase();
$case->retrieve($test);
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'
$case->save();
}
?>
如果我删除所有 case creation/update 逻辑并只回显 $test,我会得到我期望的响应。但是,有了更新逻辑,即使我简单地回显 $test,我的响应也是空的,并且案例不会得到更新。
编辑:由于出现无效入口点错误,我尝试在 include/MVC/Controller/entry_point_registry.php:[=16 中为 modules/Cases/case.php 添加入口点=]
$entry_point_registry = array(
'cases' => array('file' => 'modules/Cases/Case.php', 'auth' => false),
'takeTicket' => array('file' => 'custom/modules/Cases/assign_ticket.php', 'auth' => false),
'emailImage' => array('file' => 'modules/EmailMan/EmailImage.php', 'auth' => false),
.....
这没有用,所以我在 custom/Extension/application/Ext/EntryPointRegistry/customEntryPoint 中添加了一个条目。php:
$entry_point_registry['takeTicket'] = array(
'file' => 'custom/modules/Cases/assign_ticket.php',
'auth' => false
);
$entry_point_registry['cases'] = array(
'file' => 'modules/Cases/Case.php',
'auth' => false
);
根据提供的信息对文件进行了一些更改:
custom/modules/Cases/assign_ticket.php
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'; //Added semicolon (syntax error)
custom/Extension/application/Ext/EntryPointRegistry/customEntryPoint.php
'auth' => true //You need to be authenticated/authorised to perform saves on records
Ajax:
url: 'index.php?entryPoint=takeTicket', //If you check the Sugar docs carefully, you'll see that the URL you need to call is index.php?entryPoint={yourEntryPointRegistryKey}
我在自定义按钮上的 ajax 调用时遇到了一些问题。自定义按钮位于案例列表视图中,列表中的每个案例都有一个。单击时,此按钮应执行对自定义端点的 ajax 调用,将 assigned_user_id 更新为当前登录的用户,并重定向到与按钮关联的案例。
目前,我正在访问端点,并且可以记录通过 ajax 调用发送的案例 ID,但无法获得更新案例分配用户的调用。
这是 ajax 调用:
function take_ticket(url, id) {
$.ajax({
url: '/custom/modules/Cases/assign_ticket.php',
contentType: 'JSON',
data: {
'id': id
},
success: function(response){
window.location = url;
//alert(response);
},
error: function(response) {
alert('Error');
}
});
return false;
}
这是我创建的自定义端点(请注意,我正在对用户 ID 进行硬编码以进行测试):
<?php
if ($_GET['id']) {
$test = $_GET['id'];
updateUser($test);
}
function updateUser($test) {
$case = new aCase();
$case->retrieve($test);
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'
$case->save();
}
?>
如果我删除所有 case creation/update 逻辑并只回显 $test,我会得到我期望的响应。但是,有了更新逻辑,即使我简单地回显 $test,我的响应也是空的,并且案例不会得到更新。
编辑:由于出现无效入口点错误,我尝试在 include/MVC/Controller/entry_point_registry.php:[=16 中为 modules/Cases/case.php 添加入口点=]
$entry_point_registry = array(
'cases' => array('file' => 'modules/Cases/Case.php', 'auth' => false),
'takeTicket' => array('file' => 'custom/modules/Cases/assign_ticket.php', 'auth' => false),
'emailImage' => array('file' => 'modules/EmailMan/EmailImage.php', 'auth' => false),
.....
这没有用,所以我在 custom/Extension/application/Ext/EntryPointRegistry/customEntryPoint 中添加了一个条目。php:
$entry_point_registry['takeTicket'] = array(
'file' => 'custom/modules/Cases/assign_ticket.php',
'auth' => false
);
$entry_point_registry['cases'] = array(
'file' => 'modules/Cases/Case.php',
'auth' => false
);
根据提供的信息对文件进行了一些更改:
custom/modules/Cases/assign_ticket.php
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'; //Added semicolon (syntax error)
custom/Extension/application/Ext/EntryPointRegistry/customEntryPoint.php
'auth' => true //You need to be authenticated/authorised to perform saves on records
Ajax:
url: 'index.php?entryPoint=takeTicket', //If you check the Sugar docs carefully, you'll see that the URL you need to call is index.php?entryPoint={yourEntryPointRegistryKey}