We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 791
    • 46 Posts
    Hi All,

    This is a basic question from a relatively new snippet creator!

    We have developed a MODx snippet that pulls data from our real estate application using its API. To authenticate with the real estate API we are passing a key and shared secret which currently is hard-coded in the snippet's PHP code.

    /**
     * BDP Api Key
    */
    $apiKey = 'blahblahblahAPIkeyetc';
    
    /**
     * BDP Api Shared Secret
    */
    $sharedSecret = 'yadayadasharedsecret';
    
    /**
     * BDP Account Id
    */
    $accId = '100';
    
    /**
     * Includes Path
    */
    $incPath = 'assets/snippets/bdpweb/';
    

    We want to make the snippet more user-friendly by asking the user to enter the key, secret and ID into input boxes which will presumably be stored in the DB and accessed by the snippet as required. How do we achieve this? What's the best way of approaching this requirement? Any and all suggestions gratefully received, and any links to relevant RTFM pages.

    Thanks.
      Learning a little more each day.
    • I would store them in system (or context) setting.

      A setting with the key 'option.key' could be retreived then with the following code:
      $option = $modx->getOption('option.key', null, 'default value');

      If the system setting does not exist found, the value 'default value' is retreived.