We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14877
    • 110 Posts
    MODX 2.3.1

    Background
    For reasons I don't want to get into, over a year ago I wrote a “subsystem” for a website that was being built using MODX. To invoke the subsystem (or “functionality”) I created a web link in MODX and wrote the subsystem in much the way one would code a static website. The subsystem appears to be integrated as leaving the subsystem by clicking on a menu item (or similar link) actually invokes the appropriate MODX resource (i.e. the resource id is coded in the URL). It mimics the look and feel of the rest of the site.

    The subsystem queries a database based on user input, uses the Google MAPS API to geo-code a location (supplied by the user), computes “targets” within a specified distance and displays them on a map (using the aforementioned Google Maps API).

    I'm not as comfortable with Object-Oriented Programming as I would like to be (I started earning my living programming before the personal computer became a reality, so I'm ancient!), but grapple with it when needed. I think it is the right paradigm, though I find many of the implementations seems to make life more complicated rather than simpler. Anyway, back to the question…

    “Submit” a form invokes a PHP program (which one depends on where one is in the subsystem) that does some computation and, depending on the results, redirects to one of various pages (and this same pattern happens in various places in the subsystem). This is done by inserting a “<meta http-equiv="refresh">” tag in the header before closing off the HTML and exiting.

    $_SESSION variables are used to pass data among various “modules”. A session variable may (and often does) hold an array or even a more complex structure composed of nested arrays.

    Are place-holders stored as session variables? If so, then I can use place-holders for communications.

    Is there any straightforward way of selecting which resource is to be displayed next? Remember this decision is made by the executing PHP code. I imagine I can use a bit of a hack: set a place-holder and have a template with a “refresh” in the HTML head section having the place-holder embedded in it.

    Do controllers or plugins need to enter this picture?

    This question has been answered by BobRay. See the first response.

      __________________
      JRG
    • discuss.answer
      • 3749
      • 24,544 Posts
      I wouldn't think you'd need controllers or plugins, but I could be wrong.

      Placeholders are not stored as $_SESSION variables. They're available with $modx->getPlaceholder() and $modx->GetPlaceholders(), but they don't survive past the current request, so you'd probably have to explicitly set them from the placeholders or whatever -- setting them as $_SESSION variables would probably be more secure than any alternatives.

      Something like this might be useful (untested):

      $phs = $modx->getPlaceholders();
      foreach($phs as $key => $value) {
          $_SESSION[$key] = $value;
      }


      You may want to add a prefix to avoid collisions, depending on how unique the names are:

      $_SESSION[$key] = $prefix . '.' . $value;


      Is there any straightforward way of selecting which resource is to be displayed next?

      Sorry, I don't understand this question.

      BTW, instead of messing with the header, you can do this:

      $modx->sendRedirect($url);


      or, if you have the doc id:

      $url = $modx->makeUrl($docId, "", "", "full");
      $modx->sendRedirect($url);
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 14877
        • 110 Posts
        Quote from: BobRay at Oct 01, 2014, 06:03 PM
        I wouldn't think you'd need controllers or plugins, but I could be wrong.

        Placeholders are not stored as $_SESSION variables. They're available with $modx->getPlaceholder() and $modx->GetPlaceholders(), but they don't survive past the current request, so you'd probably have to explicitly set them from the placeholders or whatever -- setting them as $_SESSION variables would probably be more secure than any alternatives.

        Something like this might be useful (untested):

        $phs = $modx->getPlaceholders();
        foreach($phs as $key => $value) {
            $_SESSION[$key] = $value;
        }


        You may want to add a prefix to avoid collisions, depending on how unique the names are:

        $_SESSION[$key] = $prefix . '.' . $value;


        Is there any straightforward way of selecting which resource is to be displayed next?

        Sorry, I don't understand this question.

        BTW, instead of messing with the header, you can do this:

        $modx->sendRedirect($url);


        or, if you have the doc id:

        $url = $modx->makeUrl($docId, "", "", "full");
        $modx->sendRedirect($url);

        Hi Bob,

        The last code sample is exactly what I was looking for. I didn't know about $modx->sendRedirect().

        The information about place-holders is also useful. I think I should be in good shape to start integrating the code now.

        Thank you.
          __________________
          JRG
          • 3749
          • 24,544 Posts
          I'm glad I could help. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting