We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47666
    • 43 Posts
    I could not get it to work as suggested.

    Two questions…

    "3. Create a new Resource with 'blank' Template and put this into its content:"
    I don't have a "blank" template option. The two closest options are "empty" and "baseTemplate". I tried both of those.

    5. Create a snippet called 'getSessionVar' with:
    return $_SESSION[$var];
    


    Should I literally have $var or should I have one of these for each variable I want to return?

    example
    return $_SESSION[$city];
    


    Or is $var some kind of array that holds all session variables?

    This seems like a lot of work to save a few variables. I know the solution you gave me was to make my code work as is, but is there a better way to do this?




      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If PHP code is not being processed as a MODX snippet or plugin, it's "outside" of MODX. You are always better off making PHP scripts into snippets if at all possible, since the SESSION and the database, as well as a number of other MODX features, are available.

      As far as using no template - the point is to have a resource that outputs an HTML page with nothing but the data you want to return to your AJAX request. You can go to the URL in your browser and see what it's doing.

      When a requested resource is processed, MODX check for its assigned template, loads the template, then parses it to replace all of the MODX tags with the appropriate content, such as the resource's [[*pagetitle]] or [[*content]]. If a resource is assigned template #0 - the (empty) option in the template drop-down - then the resource's content is used as if it were the template instead.
        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
        • 4172
        • 5,888 Posts
        I don't have a "blank" template option. The two closest options are "empty" and "baseTemplate". I tried both of those.
        empty is the correct one.


        return $_SESSION[$var];

        Should I literally have $var or should I have one of these for each variable I want to return?

        this is the correct code with $var, because you are setting the property with the snippet-tag in the html:

        &var=`product`


        <h1>Here are some [[!getSessionVar? &var=`product`]] Insurance Quotes in [[!getSessionVar? &var=`city`]] </h1>
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 47666
          • 43 Posts
          I just purchased and downloaded BobRay's MODX: The Official Guide. I'm planning on really digging into the guide next week, but for now to get this issue worked out, what am I looking for? What are the best practices for creating session variables inside of ModX?

          Should I take the php files inside my script folder and make them all resource files? Or should I break them apart into snippets by function.

          Is this even covered in MODX: The Official Guide?

          Sorry, but I'm trying to get my head around the workflow in modX. I understand the basics for the html front end, but the backend is giving me trouble.
            • 4172
            • 5,888 Posts
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 47666
              • 43 Posts
              Bruno I tried it but it didn't work. I'm pretty sure I followed your directions to the t. Thanks again for the through explanation. Does modX have any kind of debugging for this kind of thing? Other than that I think I just need to work through that manual and get my head around the right way to handle this stuff.
                • 4172
                • 5,888 Posts
                the first thing to check is, does the ajax-resource work.

                what is the generated url here:

                $.ajax({
                    type: 'POST',
                    url: "[[~99]]",
                    cache: false,
                    datatype: "html",
                    success: function(data){
                        …            
                    }
                });


                does this ajax-request return anything(firebug)?
                If not, does it return anything, when you replace your snippet-call there with some content?

                If this everthing is working so far, you will need to debug your included script.
                Is it included correctly.
                Is the path to the file correct and so on.

                Let us know how it goes at each step.

                'It does not work' is nothing we can help with.
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 47666
                  • 43 Posts
                  Sorry about that…The session vars are not being output. The page still loads ok though.

                  It's generating the right page (i think)
                  url: "index.php?id=17"
                  


                  id 17 is the resource doc include process form 1 which contains:
                  [[!includeScript? &include=`processForm1`]]
                  


                  Here is my includeScript

                  <?php
                  include $modx->getOption(base_path) . 'scripts/' . $include . '.php';
                  

                  How do I check to see what that is generating?
                    • 47666
                    • 43 Posts
                    I just read in the guide that:


                    Files that need to be web-accessible are located below this directory (where component_name is the name of the component):
                    assets/components/component_name

                    Right now my scripts folder is on the main directory (which shows up inside the manager/dashboard in the "media" folder) which is at the same level as the assets folder. Should the scripts folder not be on the main directory?
                      • 47666
                      • 43 Posts
                      Another question. So as I have found some other posts on session variables it sounds like they work exactly the same ( compared to working outside of ModX) as long as all my scripts are moved into snippets. Is that correct?