Skip to content

Instantly share code, notes, and snippets.

@mmarum-sugarcrm
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarum-sugarcrm/84a0d0883c2423ae4c38 to your computer and use it in GitHub Desktop.
Save mmarum-sugarcrm/84a0d0883c2423ae4c38 to your computer and use it in GitHub Desktop.
Sugar 7 Mobile API Logic Hook example
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_routing'] = Array();
$hook_array['after_routing'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'after_routing mobile logic hook',
//The PHP file where your class is located.
'custom/MobileApiLogicHook.php',
//The class the method is in.
'MobileApiLogicHook',
//The method to call.
'logMobileAfterRouting'
);
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/**
* Example Mobile API Logic Hooks class
**/
class MobileApiLogicHook
{
/**
* Logic hook function tied to 'after_routing' event
*/
function logMobileAfterRouting($event, $arguments)
{
//Sugar Logger
global $log;
//If request came from a Mobile platform
if($arguments['api']->platform == "mobile"){
$path = $arguments['api']->getRequest()->getPath();
//Write request path to sugarcrm.log file
$log->fatal("Mobile request to " . json_encode($path));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment