We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    I am experiencing a weird PHP problem, and I am seeing this on two different web servers. I’m going crazy trying to solve this so I’m hoping someone can help. It’s weird because I’ve used PHP a lot and found it to be reliable, but now I’m a bit worried. Hopefully I am making a stupid mistake somewhere.

    I edited the document.parser.class.inc.php to generate a log file to show the execution flow of a specific part of the file.

    At the start of the file I added:

    function write_to_log($str) {
        if($fd = @fopen("/home/andy/public_html/beverleyinpictures/modx.log",  "a")) {
        fputs($fd, $str);
        fclose($fd);
        }
    }
    


    I then added a call to write_to_log() at the start of the function getDocumentIdentifier:

      function getDocumentIdentifier($method) {
        write_to_log("method=".$method.", q=".$_REQUEST['q']." id=".$_REQUEST['id']."\n");
        // function to test the query and find the retrieval method
        $docIdentifier= $this->config['site_start'];
    


    I then added two calls to write_to_log() around the only call to getDocumentIdentifier in the whole file:

    write_to_log("here1\n");
    $this->documentIdentifier = $this->getDocumentIdentifier($this->documentMethod);
    write_to_log("here2\n");
    


    Here is the output of my log file:

    here1
    method=alias, q=beverleyminster.html id=
    here2
    here1
    method=alias, q=suninn.html id=
    here2
    method=id, q=suninn.html id=
    method=id, q=suninn.html id=0
    here1
    method=alias, q=map.html id=
    here2
    


    What you see here is a successful call of getDocumentIdentifier, with q=beverleyminster.html. Then getDocumentIdentifier is called again with q=suninn.html. This completes then inexplicably it is called twice more. However "here1" and "here2" don’t appear. This means that the second and third times the function was called were not from the only function call that exists. The function doesn’t have a loop in it. Also where is the method "id" coming from for the second and third calls?

    This problem is stopping friendly URLs from working for me, so I really hope to get this solved. Here is some server info:

    MODx 0.9.2.1 rev 1005
    PHP 4.4.0 and 4.4.1
    Gentoo Linux 2006.0 (2.6.15)
    Apache 2

    Thanks for the help!!! regards, Andy
      • 727
      • 502 Posts
      I think I’ve solved the problem. Never use the following in a snippet otherwise it will break friendly URLs:

      $id = $modx->getDocumentIdentifier('id');
      


      Instead use:

      $id = $modx->documentObject['id'];
      


      Andy
        • 22303 MODX Staff
        • 10,725 Posts
        Quote from: ajayre at Sep 08, 2006, 10:46 AM

        I think I’ve solved the problem. Never use the following in a snippet otherwise it will break friendly URLs:

        $id = $modx->getDocumentIdentifier('id');
        


        Instead use:

        $id = $modx->documentObject['id'];
        


        Andy


        Indeed; very good catch Andy -- and thanks for sharing the experience. In the future, there will be a much larger distinction between public API methods which are intended for use in MODx add-ons, and those that are private and only meant for use within the core.