We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7155
    • 160 Posts
    how do i access the configuration variables I created using the module manager?

    I need to access them from code
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      They are available to code within the module as variables. For example, &path=Path;text;assets/modules/mymodule/ would be available as $path.

      Don’t forget that if you want to access it within a function, you would most likely have to do a global $path; in the beginning of your function, unless you pass it to the function as an argument.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 7231
        • 4,205 Posts
        &path=Path;text;assets/modules/mymodule/
        Why do we need the Path;text part of the declaration? Would this work: &path=assets/modules/mymodule/
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 7155
          • 160 Posts
          Quote from: sottwell at Aug 27, 2008, 06:08 AM

          They are available to code within the module as variables. For example, &path=Path;text;assets/modules/mymodule/ would be available as $path.

          Don’t forget that if you want to access it within a function, you would most likely have to do a global $path; in the beginning of your function, unless you pass it to the function as an argument.
          thanks once again

          one more question though, is there no risk of variable conflict? are there any reserved words I have to avoid?
            • 7155
            • 160 Posts
            I still cant access the configuration parameters

            I want to access them from within the Module code. I have enabled parameter sharing and have used the global keyword in the function, still nothing:

            This is part of the configuration string:

            &status=Status;list;online,offline;online &offline_message=Offline Message;string;Down for maintenance.Please check back again later.

            I have a function in a class (if thats important):


            class MyClass{

            public function functionName
            {
            global $status,$offline_message;


            echo $status; //displays nothing
            echo $offline_message; //displays nothing too!!
            }

            }
              • 7155
              • 160 Posts
              Quote from: dev_cw at Aug 27, 2008, 06:21 AM

              &path=Path;text;assets/modules/mymodule/
              Why do we need the Path;text part of the declaration? Would this work: &path=assets/modules/mymodule/
              From here:
              http://www.modxcms.com/module-configuration.html

              It states that it is in the form

              &name = Description;datatype;value
              

              path is the variable
              Path is the description(or lable of the text field)
                • 7231
                • 4,205 Posts
                designetic@ Thanks. I knew I had read about that before someplace...who would have guessed it was in the docs rolleyes
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 7155
                  • 160 Posts
                  do I have to use the GUID?

                  I wish it was documented somewhere because it was left hanging in the wiki
                    • 7155
                    • 160 Posts
                    I was pressed for time, so after alot of code-reading, I reused the following code in my function from the modx codebase

                    global $modx;
                    // get module data
                    $sql = "SELECT * " .
                    "FROM ".$modx->getFullTableName("site_modules")." " .
                    "WHERE name = ’ModuleName’"; //your own module name

                    $rs = mysql_query($sql);

                    $content = mysql_fetch_assoc($rs);

                    // load module configuration
                    $parameter = array();
                    if(!empty($content["properties"]))
                    {
                    $tmpParams = explode("&",$content["properties"]);
                    for($x=0; $x<count($tmpParams); $x++)
                    {
                    $pTmp = explode("=", $tmpParams[$x]);
                    $pvTmp = explode(";", trim($pTmp[1]));
                    if ($pvTmp[1]==’list’ && $pvTmp[3]!="") $parameter[$pTmp[0]] = $pvTmp[3]; //list default
                    else if($pvTmp[1]!=’list’ && $pvTmp[2]!="") $parameter[$pTmp[0]] = $pvTmp[2];
                    }
                    }
                    extract($parameter, EXTR_SKIP);