1

我想通过 Module Loader 模块为 Sugar 实例定义我自己的 API。如何在不使用chdir命令的情况下在 SugarCRM 模块中定义自己的 SOAP/REST API?

在文档中,解释以升级安全方式扩展 REST API 的方式包括 chdir 命令:http: //developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0 -Chapter%202%20Application%20Framework.html#9001337

但是chdir命令被使用模块加载器限制的安装禁止:http: //developers.sugarcrm.com/wordpress/2009/08/14/module-loader-restrictions/

当这些限制打开时,不允许在代码中使用 chdir 命令,例如 Sugar on Demand 实例就是这种情况。

是否有任何其他方式来定义自定义 REST API?如何仅通过使用模块将 REST API 添加到 SugarCRM?谢谢你。

4

2 回答 2

2

对于那些会遇到同样问题的人,我找到了一个足够的解决方法。

定义 REST(或 SOAP)API 的文件可以放在 Sugar 基本路径中。这样就不需要 chdir。例如,您可以调用它 myapi.php:

<?php
$webservice_class = 'SugarRestService_v2_custom';
$webservice_path = 'custom/myapi/v2/SugarRestService_v2_custom.php';
$registry_class = 'registry_custom';
$registry_path = 'custom/myapi/v2/registry_custom.php';
$webservice_impl_class = 'SugarRestServiceImpl_v2_custom';
$location = 'custom/myapi/v2/rest.php';
require_once('service/core/webservice.php');

将文件放入模块中的特殊目录中,例如将其命名为basepath。然后,在您的 manifest.php 文件中,您像这样声明它:

'copy' => array (
0 => 
array (
  'from' => '<basepath>/basepath',
  'to' => '.',
),
...
于 2011-04-28T06:30:33.430 回答
2

我们计划在 SugarCRM 的未来版本中解决此问题(有关详细信息,请参阅http://www.sugarcrm.com/crm/support/bugs.html#issue_43734上的错误 43734)。

要在您的实例上解决此问题,只需在 service/core/webservice.php 文件的开头添加以下行:

chdir(dirname(__FILE__).'/../../');
于 2011-05-03T02:49:15.780 回答