We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17691
    • 22 Posts
    Hi!

    I have a problem with my module code. I make a blank module and i include a main file (main.php). This file is saved in assets/modules/test. In the same directory there is a file named functions.php. In the functions.php there are some self made PHP functions. The functions.php is included in the main.php.
    My problem is that the main.php code is displayed normal when i start the module but the code of the functions.php doesn’t shown.

    Let’s give me an example:

    The module code:
    include ("../assets/modules/test/main.php");


    The main.php:
    <?php
    echo "The main.php<br>";
    include ("../assets/modules/test/functions.php");
    ?>
    


    The functions.php:
    <?php
    echo "The functions.php";
    ?>
    


    My output is only
    The main.php

    When i remove the PHP Tags (<?php ?>) in the functions.php my output is
    The main.php
    echo"The functions.php";


    Can anybody tell me what my problem is???
    Thanks alot!

    greetings, Lupo
      • 10449
      • 956 Posts
      try absolute paths, or:

      $basePath = $modx->config[’base_path’];
      include_once $basePath.’assets/modules/test/foo.php’;
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Using relative paths can be tricky; relative to what?

        If you include a file from the page in the Manager, then you need the ../ bit to move up from the /manager folder, then back down to the assets folder.

        But if you have a file in that assets/modules/test folder that includes another file from the same folder, you don’t want any of that, a relative path would indicate the same folder.

        It’s the same in css files when linking to background images. The path to the image is relative to the css file, not to the page using that css file.
          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
          • 17691
          • 22 Posts
          Sorry scottwell! I also think the same first. But it works with both methods.

          But this is not the problem. Now i found the really problem.
          I have a function for the output. In this function i use a global variable for my database name. I define the variable for the database name in the main.php. In the function.php i use the global variable to read the content of the database. I get a blank output because the global variable lost their value. Hmmm...
          The code of the module is OK because when i open the main.php directly in the browser i get the complete output.

          When i define the variable as superglobal ($_SESSION) then it will works.

          Is this a problem in modules when i use "normal" global variables? Thx!!!