We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m working on a snippet that needs to read a file using fopen() in the php code.

    I prepended the base_path to the filename but the error message contains just the relative path to the file.

    I put in this code to check the path and it prints "base path:

    global $modx;
    $ppath = $modx->config[’base_path’];
    echo "base path: ",$ppath,"
    ";

    I thought base_path was available everywhere. Is there something I need to do to have base_path set, or have I made some stupid typo?

    (base_url and site_url are also unset)

    Bob
      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
      • 27376
      • 576 Posts
      Where are you trying to access the [tt]$modx[/tt] variable from? In other words, where/when is this script being executed?
        • 3749
        • 24,544 Posts
        Quote from: sirlancelot at Jun 03, 2007, 01:31 AM

        Where are you trying to access the [tt]$modx[/tt] variable from? In other words, where/when is this script being executed?

        In the php code of an include file for a snippet. It’s a nested include. Tthe snippet includes a file that includes another file that includes the one with this code.

        Bob
          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
          • 5727
          • 160 Posts
          I’m not sure but I think this variable is gone in 0.9.6... replaced by something else, but I ain’t sure (guess I shouldn’t post in the first place...)
          [Edit: it’s not gone! (see post below)]

          Did you try:

          <?php
              print_r( $modx->config );
          ?>
          
            Olivier Deland
            Montreal, Canada - Web Developer
            • 22303 MODX Staff
            • 10,725 Posts
            $modx->config[’base_path’] is definitely not gone; it is one of the most used variables in the configuration! However, you could also use the new constants...

            MODX_BASE_PATH
            MODX_BASE_URL

            ...but it seems to me that you are just not getting access to the MODx variable ($modx) for some reason.
              • 3749
              • 24,544 Posts
              Quote from: OpenGeek at Jun 03, 2007, 12:07 PM

              $modx->config[’base_path’] is definitely not gone; it is one of the most used variables in the configuration! However, you could also use the new constants...

              MODX_BASE_PATH
              MODX_BASE_URL

              ...but it seems to me that you are just not getting access to the MODx variable ($modx) for some reason.

              Agreed. Other snippets that use $modx are working ok but it doesn’t seem to be available in this one.

              The file with the unresponsive code (myfile.php) is reached this way:

              <form action="[(base_url)]assets/snippets/myfile/myfile.php" method="post">

              so it looks like base_url is available there, but I can’t seem to access $modx from the page it triggers.

              Bob Ray, Official MODx weirdness magnet wink
                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
                • 22303 MODX Staff
                • 10,725 Posts
                You are posting to that php file, so it would have to do everything MODx’s index.php does. I don’t think that’s what you are intending. You need to post it to the page, i.e. action="[~[*id*]~]", that you are calling this snippet on...
                  • 3749
                  • 24,544 Posts
                  Quote from: OpenGeek at Jun 03, 2007, 04:31 PM

                  You are posting to that php file, so it would have to do everything MODx’s index.php does. I don’t think that’s what you are intending. You need to post it to the page, i.e. action="[~[*id*]~]", that you are calling this snippet on...

                  Excellent point. I’m trying to snippetize someone else’s code (scform) that bounces back and forth between several php files and reads three different config files. It’s a lightweight alternative to eform that creates a simple contact form with a drop-down list of recipients (without involving email addresses until the final processing) that I thought might be useful for people (including me) that have struggled with eform. It has excellent defenses against would-be spammers.

                  It works now if I hard code the paths, so I may be able to just pass the path as a variable in the post.

                  I think part of the point of all the separate files is to make it harder to harvest the email addresses. It may be easier to re-code it from scratch, though, to make a decent snippet out of it.

                  Bob
                    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