Define own REST API in SugarCRM module without using chdir
I would like to define my own API to Sugar instances via a Module Loader module. How can I define my own SOAP/REST API in a SugarCRM module without using the chdir command?
In the documentation, the way it is explained, to extend the REST APIs in an upgrade-safe manner includes the chdir command: http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9001337
However the chdir command is banned by installations that use Module Loader restrictions: http://developers.sugarcrm.com/wordpress/2009/08/14/module-loader-restrictions/
Having a chdir command in the code is not allowed when these restrictions are switched on, which is the case for example for Sugar on Demand instances.
Are there any other ways to define custom REST A开发者_如何学编程PIs? How can I add REST APIs to SugarCRM via using a module only? Thank you.
For those that will run into the same issue, I have found an adequate workaround.
The file that defines the REST (or SOAP) API can be placed in the Sugar base path. That way a chdir isn't necessary. You can call it for example 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');
Place the file into a special directory in your module, for example call it basepath. Then, in your manifest.php file you declare it like this:
'copy' => array (
0 =>
array (
'from' => '<basepath>/basepath',
'to' => '.',
),
...
We plan to fix this in a future release of SugarCRM ( see the bug 43734 at http://www.sugarcrm.com/crm/support/bugs.html#issue_43734 for more details ).
To fix this on your instance, simply add this line at the beginning of the service/core/webservice.php file:
chdir(dirname(__FILE__).'/../../');
精彩评论