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
    Quote from: OpenGeek at Dec 02, 2007, 07:26 PM

    No, base_path will never be an empty string; it should always mirror MODX_BASE_PATH which is a constant.
    I certainly would have thought so, but when I moved veriword.php to my snippet directory and put this code at the top:
    require "../../../manager/includes/config.inc.php"; // required for $modx to work
    $spformPath = "assets/snippets/spform/";  
    require $modx->config['base_path'].$spformPath."spfconfig.cfg.php";


    The first require succeeds but the second fails. When I tested $modx->config[’base_path’] there, it was definitely an empty string. Maybe there’s something I’m missing (there often is tongue ).

    Maybe there’s something wrong with my test of $modx->config[’base_path’]. I couldn’t use any output there, so I put this code just below the code above:

    if (strlen($modx->config[’base_path’]) >= 1) {
    exit;
    }
    The file exits and no image is produced unless I change ">=1" to "<1", then it runs fine.
    Using MODX_BASE_PATH gives the same result.

    The veriword file is accessed by a URL in an img tag.

    Looking at config.inc.php, it appears that $base_path could be set to "" and MODX_BASE_PATH is then set to $base_path:
    $base_path= $pth . (substr($pth, -1) != "/" && substr($pth, -1) != "\\" ? "/" : "");
    if (!defined('MODX_BASE_PATH')) define('MODX_BASE_PATH', $base_path);

    I’m sure this could never happen in a regular snippet but it looks like the way this code is accessed via an img tag, makes the first part of the $base_path conditional false.

    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
      • 22303 MODX Staff
      • 10,725 Posts
      That’s an error in the way that specific piece of code works and a separate issue. Including the config file like this is hackish at best and a workaround for several features in the current code that require requests directly to a resource. Another of the reasons I endeavored to re-engineer the core. But anyway, the real issue here is two-fold:

      • including the config.inc.php file does not give you access to a $modx object1
      • to be safer (and faster), certain variables need to be defined first before including the config file, as occurs in the index.php file (see code below for example)
      <?php
      // initialize the variables prior to grabbing the config file
      $database_type = '';
      $database_server = '';
      $database_user = '';
      $database_password = '';
      $dbase = '';
      $table_prefix = '';
      $base_url = '';
      $base_path = '';
      
      // grab the config file
      include(dirname(__FILE__).'/manager/includes/config.inc.php');
      ?>

      Following the execution of that code, you have access to those variables and any defined in the config file itself; this includes the constants (e.g. MODX_BASE_PATH). But $modx simply doesn’t exist at that point.


      1 -- As of 0.9.6.1, you should be able to access the $modx object very easily, by simply defining MODX_API_MODE as true and including the MODx index.php file (no including the config file or defining variables required), e.g.
      <?php
      // your code here
      
      define('MODX_API_MODE', true);
      include(dirname(__FILE__) . '/index.php');
      
      // your code with access to $modx here
      ?>