问题
I am customizing the SugarCRM. At some point I need to store some custom values to the database while user creates the record. I tried to use Triggers, but it didn't fulfill the requirement. So I need to write that in PHP code.
My question is, where to write this code.
回答1:
Use logic hooks (after_save or before_save e.g.) on the module's save action.
Create a logic_hooks.php in custom/modules/myModule/
<? $hook_array = Array(); $hook_array['after_save'] = Array(); $hook_array['after_save'][] = Array( 0, 'myName', 'custom/modules/myModule/logic_hooks/file.php', 'myClass', 'myMethod' ); ?>Create file.php in /custom/modules/myModule/logic_hooks/
<?php class myClass{ function myMethod(&$bean, $event, $arguments){ // Do something with $bean (e.g. store the custom DB value) } } ?>
For more info see: this link.
回答2:
Make sure that your_php_file.php is executable by apache. It could be that or possibly a misspelling? See if there is anything in your apache log files.
来源:https://stackoverflow.com/questions/7975679/sugarcrm-writing-custom-code-while-saving-the-record