We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Browsing through modExtra and Doodles I noticed that the classes modExtra and Doodles are used to hold basic config data.

    I would like to do the same for my module and also use such a config class for config data which is stored in the System Settings, so that I only have to access the settings once when the config class is created. The different settings can then be made available through specific convenience methods. As an example:

    //in the initialize method of my config object:
    $config = $modx->getConfig();
    $this->currency = $config['currency'];
    ...etc...
    
    //a convenience method:
    public function getCurrency() {
      return $this->currency;
    }
    


    To access the config object, I was thinking of doing the following in the initialise method of the config object:
    $modx->myConfig = $this;
    


    Using the capabilities of PHP to dynamically create instance variables, I would have access to my config throughout the PHP layer of my module.

    Is this considered "good behaviour" in MODx or are there better ways of achieving the above?
      MODx Revolution / MAMP / OS X
      • 4172
      • 5,888 Posts
      if you want to have access to your object and all its methods and properties
      you can create your instance into modx
      $modx->myobject = new Myclass($modx);
      $modx->myobject->initialize();
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 27519
        • 275 Posts
        Thanks!
          MODx Revolution / MAMP / OS X