Results 1 to 3 of 3

Thread: custom constants

  1. #1
    sequoiaben is offline Member
    Join Date
    Aug 2010
    Posts
    11

    Default custom constants

    Hello,

    While customizing sugar, we're finding the need to create some constants that we use in our own custom code. These are mostly the names of various teams, for example:

    define('SALES_INBOUND','Sales (Internal) - Inbound');

    Right now we have this in config_override.php, however I'm not sure if this is the best place for us to define our constants. Like all our other custom code, I'd like to put this in the /custom folder.

    If anyone has experience here and can provide suggestions on where to "correctly" define our custom constants, that would be very much appreciated.

    Thanks in Advance,
    Ben

  2. #2
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: custom constants

    This is probably not the 'correct' way to do this, but what I did was I created a custom module for this purpose, i.e. "Custom Settings" or "Custom Control Panel". I then restricted the module to only having one entry (you can do this multiple ways, essentially deleting a record every time one is saved). Every field in this module related to a constant in my code and was accessible by a sql query.

    Although this is more for modifiable fields (for example, one is a list of all the phrases we're using for when people manually reply to a newsletter wishing to opt out) it does essentially give the global perspective you're looking for in an upgrade safe manner.

    However, there are some shortcomings that make it less than ideal for what you're looking for, as well as for me, so if others have answers to this question I wouldn't mind hearing them as well.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  3. #3
    sequoiaben is offline Member
    Join Date
    Aug 2010
    Posts
    11

    Default Re: custom constants

    Hello,

    Thanks Robert for the recommendation. Just wanted to reply because we found a good solution and this might help someone else in the future. The constant in the example is the name of our outbound sales team.

    We did the following:

    - added our custom constants into the config table, for example:

    PHP Code:
    INSERT INTO config (categorynamevalueVALUES ('AppSettings''outbound_team_name''DEFAULT TEAM NAME'); 
    - created the file: custom/includes/get_constants.php to grab the info from the DB (there might be a more "proper" way to do this). For example:

    PHP Code:
    function get_sales_outbound_team_name()    {

        
    $administration = new Administration();
        
    $administration->retrieveSettings('AppSettings');

        if(empty(
    $administration->settings['AppSettings_sales_outbound'])) {
            
    $GLOBALS['log']->error("get_sales_outbound_team_name: sales_outbound constant not found .. you need to run custom/scripts/sql/install_constants.sql");
        }

        else {    
            
    $outbound_team $administration->settings['AppSettings_sales_outbound'];
            return 
    $outbound_team;
        }
        

    - we also created custom/scripts/sql/install_constants.php ... which inserts the default constants into the DB.

    Thanks,
    Ben

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 2010-05-11, 10:30 AM
  2. Replies: 1
    Last Post: 2009-03-25, 12:26 AM
  3. Calculated Fields and Constants
    By cygnusceo in forum Developer Tutorials
    Replies: 2
    Last Post: 2008-12-29, 03:15 PM
  4. Replies: 4
    Last Post: 2007-05-17, 08:39 PM
  5. New constants in 4.2.1a language files
    By Markku in forum Translators
    Replies: 16
    Last Post: 2006-07-19, 06:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •