I was working on applying some rules to SugarCRM this week. The logic hooks have allowed this to be build in before saving or deleting a file.
Thinking about the UI and the actions, I wanted to create a set of redirects which would show an error message if something could not take place. Normally, the logic hook runs through and quietly does it tasks before returning to the screen. Not very useful when you need to show a message.
You can use a native header(); call if you really want to in the logic_hook. However this may cause issues if the base url of your Sugar instances changes. Using redirect() means that if you are internally redirecting, then the script will be aware of the Sugar root. You also do not have to be aware of moving between http:// and https:// which you would have to do with header(). Of course, it could be used to help the user to a different script, service or site if required.
The second issue was showing the error message for the user. Using the static appendErrorMessage() function in the SugarApplication API, you can stack up error messages until the View that reloads.
I’ve put together a quick gist to put it together and extend the SugarCRM example.