We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26903
    • 1,336 Posts
    undecided
    Hello,

    I’m converting a handcrafted html/php site into a Modx hosted one, so far all is well, I’m fairly pleased with Modx, however I have
    come across this problem.

    I am including an external php file from a snippet, in this file I have the following construct(abbreviated for clarity):-

    function Generate()
    {
    Line 1
    Line 2
    return $output
    }

    //Main entry point
    if ( isset(somevariable))
    {
    $chunkoutput="Default"
    $chunkoutput = Generate();
    $modx->setPlaceHolder(’mygeneration’,$chunkoutput)
    }

    Ok, this always returns null for $chunkoutput, if I comment out the call to Generate() it correctly returns the string "Default" as I’ve set.
    If I comment out the call to Generate() and include the function body inline ie place Line 1, Line 2 above the placeholder call it also produces the correct output.

    Why is the output variable set to null if I use a function call here?

    No errors in the error-log of any kind, am I missing something obvious here? Can I turn on some debug inside modx to show me the actual code its generating?

    Any pointers please. This is a bit of a show stopper at the moment.


      Use MODx, or the cat gets it!
      • 10449
      • 956 Posts
      what kind of stuff is line 1, line 2 doing? Also, does the original (full) generate() function accept parameters or not?
        • 7923
        • 4,213 Posts
        You can see parsing errors from system log at modx manager.

        If you use $modx object in your function, use global $modx; in the beginning of the function to make it available.

        Also, I suggest to wrap the functions in !function_exists block if the resource is called multiple times on a page.

        Check also the Creating Snippets page at MODx wiki to get more tips..


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 26903
          • 1,336 Posts
          OK thanks for the pointers,

          I’ll look at the log, didnt realise the modx object had to be global, ta, I’m pretty sure I’m not calling this twice but I’ll wrap it anyway.
          When solved I’ll post the outcome her.

          As a total aside here I run Centos5(RHEL 5) on my production server with selinux turned on(this is a must), on my dev box its turned off for convenience while I’m developing. I’ve already noticed that modx(actually httpd does) throws up some avc denied errors here, I’ll get round to looking at this before we port over. We usually tweak the selinux policy on the server to accomodate things like this that dont have a policy yet as such. Would anybody be interested in this? Where the best place to post stuff like this on the forum?

          I also run with mod_security but thats already covered on the site.

          Thanks again.
            Use MODx, or the cat gets it!
            • 7923
            • 4,213 Posts
            Quote from: shamblett at Feb 07, 2008, 03:26 AM

            Would anybody be interested in this? Where the best place to post stuff like this on the forum?
            I’m sure it would be helpfull information. You could create an article in wiki.modxcms.com about it. Thanks!


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 26903
              • 1,336 Posts
              smiley
              OK sussed it, then Generate() function was using a global variable in its processing, this varable was always null inside here even with the correct ’global decs as in the original code. Dont know why, no errors anywhere, OK if I call The function like this it works OK :-

              $word = "Something";

              function Generate($inputword)
              (

              if (isset(somecondition))
              {
              global $word;
              Generate($word);
              ........
              .......
              }

              ie pass the variable to the function at this point when it is in scope and valid
                Use MODx, or the cat gets it!
                • 26903
                • 1,336 Posts
                Sorry about the above reply, the text got a bit mangled, but I think you get the picture, this is actually better than the original code as we are taking reliance of globals and using better scoping. OK, when I get to do the port I’ll write up about the selinux stuff on the wiki, may even be better to document an install on/port to Centos as a whole and include everything else I find. Thanks again.
                smiley
                  Use MODx, or the cat gets it!