We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23054
    • 62 Posts
    In order to use a PHP-Editor and store it in files I would like to know if the following one is possible:

    Create my own PHP files and classes, save them somewhere within the manager file system and assign them to MODx.

    "Module" sounds pretty interesting but I could not find a way to save the new created module as file ?

    If that is possible could I use this module within snippets and document code ?
      • 33453
      • 141 Posts
      Is this what you are after?
        • 23054
        • 62 Posts
        Yes, it could be indeed - I will try it later this day

        And is there a way to integrate PHP code into document code ?
        I tried without success
        <?php echo phpversion() ?>

        The code is completely ignored and visible in generated html source code (but not displayed)

        If that is possible I could source out my database logic from MODx - that would it make much easier to reuse the source code somewhere else
        • That’s what snippets and TVs are for.
            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
            • 23054
            • 62 Posts
            Quote from: sottwell at Jul 08, 2006, 10:15 AM

            That’s what snippets and TVs are for.

            I know - but I need to pass a parameter array to a function - so is there a way to create a parameter array within snippet ?

            document

            [!snippet?&p1=...&p2=... ...!]

            snippet
            get_parameter_list_and _make_array ?
              • 4041
              • 788 Posts
              I needed this same functionality for my soon to be released Geshi Max snippet to have an array in the snippet to highlight specific line numbers. Here’s how I solved my problem...

              I created a folder in the assets folder named helperfunctions.

              Inside that folder I have a file which holds all my specific functions.( I got this function from the php.net site) This particular function is as follows:
              function explodearray($delimeter, $string){
                 for ($i = 0; $i < strlen($string); $i++){
                     if ($string{$i} == '"'){
                         if ($insidequotes)
                             $insidequotes = false;
                         else
                             $insidequotes = true;
                     }else if ($string{$i} == $delimeter){
                         if ($insidequotes){
                             $currentelement .= $string{$i};
                         }else{
                          $returnexplodearray[$elementcount++] = $currentelement;
                          $currentelement = '';
                         }
                     }else{
                         $currentelement .= $string{$i};
                     }
                }
                 $returnexplodearray[$elementcount++] = $currentelement;
                 return $returnexplodearray;
              }


              Then in my snippet which needs to grab the parameters I used the tip provided by OpenGeek (linked in post above) to include the function file.


              include_once($modx->config[’base_path’] . ’assets/frsfunctions/frsfunctions.php’);
              $newarray =explodearray(",", $sarray);

              the snippet call is like so: [[snippet?sarray=1,4,9,10,20]]



                xforum
                http://frsbuilders.net (under construction) forum for evolution
              • Alternatively, you could also use a snippet, or a plugin, to save the array as a MODx Placeholder:
                $modx->setPlaceholder('myArray', $myArray);

                which can then be retrieved by another snippet or plugin:
                $myArray= & $modx->getPlaceholder('myArray');
                  • 23054
                  • 62 Posts
                  Thanks for the answers - the are really helpfull to source out my database logic from MODx and to reuse the source code
                    • 23054
                    • 62 Posts
                    I was too early pleased

                    How to get the complete parameter string ?
                    ?key_1=val_1&key_2=val_2 ...

                    I need the keys and values for further processing.
                    • If you mean the parameter string from the client request, you get that with $_REQUEST or $_GET or $_POST as appropriate. If you mean the snippet parameter string, each will be set as a variable with the key as the name, within the scope of the snippet. Your var names would simply be $key_1, $key_2, ...