We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2611
    • 394 Posts
    I hope i can explain this right...i’ve created a resource that includes a snippet.
    The snippet includes a PHP file. In this PHP file i’ve scripted my own custom url
    handling. I just want a user to be able to go to:

    /mycustomurl/customplace/customaction

    Funny thing is, everything works like a charm...but ModX insists on sending the internal
    404 page not found header. This is in particulair frustrating with ExtJS ajax requests
    since it only ends up in the failure handler although it gets a good valid response ({success: true})

    This behaviour is good, and it’s possible i’m going about
    this totally wrong.

    My main question is, how can i disable or adjust the 404 handling.
    My 2nd question is, i’m i going wrong about this? smiley

    I just want to use the API and power of ModX. I return templates and stuff and even
    create my own smarty instance. The whole script is custom, just build on ModX.

    Please help me out here.
      Follow me on twitter: @b03tz
      Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
      CodeMaster
      • 22303 MODX Staff
      • 10,725 Posts
      Create a Plugin to handle it the way you want to and attach it to OnPageNotFound. Done!
        • 2611
        • 394 Posts
        Hey,

        Thanks for your response. I’ve already tried this...but my question is more
        HOW to intercept the 404 rather then where.

        Modx sets a 404 header, how can i supress that or change it’s behaviour.
          Follow me on twitter: @b03tz
          Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
          CodeMaster
          • 22303 MODX Staff
          • 10,725 Posts
          By creating a Plugin that executes on the OnPageNotFound event? This is how you intercept the behavior and modify it.
            • 7455
            • 2,204 Posts
            so could you just return null? or something?

            what options /variables do we have to work with? on that event?

            Dimmy
              follow me on twitter: @dimmy01
              • 22303 MODX Staff
              • 10,725 Posts
              See http://modxcms.com/forums/index.php/topic,41502.msg249684.html#msg249684 for an example. You have access to any $modx, session, request, and any other globals you would normally have access to.
                • 2611
                • 394 Posts
                This really frustrates me! I cannot get it to work...headers sent by response that works (an actual file):

                Response Headersview source
                Date	Thu, 29 Apr 2010 14:37:07 GMT
                Server	Apache/2.0.52 (CentOS)
                X-Powered-By	PHP/5.2.9
                Expires	Thu, 19 Nov 1981 08:52:00 GMT
                Cache-Control	no-store, no-cache, must-revalidate, post-check=0, pre-check=0
                Pragma	no-cache
                Set-Cookie	PHPSESSID=7bggqo9a3qm8i71mt5lp3rehe6; path=/
                Content-Length	1368
                Connection	close
                Content-Type	text/html; charset=UTF-8


                Headers that return a 404 not found error in Ext conn.request (request to a virtual file using ModX eg. /dir/virtualpath/):

                Response Headersview source
                Date	Thu, 29 Apr 2010 14:34:44 GMT
                Server	Apache/2.0.52 (CentOS)
                X-Powered-By	PHP/5.2.9
                Expires	Thu, 19 Nov 1981 08:52:00 GMT
                Cache-Control	no-store, no-cache, must-revalidate, post-check=0, pre-check=0
                Pragma	no-cache
                Set-Cookie	PHPSESSID=7bggqo9a3qm8i71mt5lp3rehe6; path=/
                Content-Length	67
                Connection	close
                Content-Type	text/html; charset=UTF-8


                They are exactly the same...why does it say 404? :S
                  Follow me on twitter: @b03tz
                  Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
                  CodeMaster
                  • 2611
                  • 394 Posts
                  I’ve solved it now by actually adding a PHP header:

                  header('HTTP/1.1 200 OK');


                  But i don’t think this is the way...
                    Follow me on twitter: @b03tz
                    Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
                    CodeMaster
                    • 22303 MODX Staff
                    • 10,725 Posts
                    You are supposed to call $modx->sendForward() as in the example, which takes care of setting the header huh
                      • 2611
                      • 394 Posts
                      I’m sorry but i really don’t understand how. My script is already in the
                      good position...the URL that get’s requested, also gets served. Why would
                      i need a forward then? Doesn’t it redirect to another page...?

                      As i said in my first post, everything works like a charm...every URL goes
                      where it’s supposed to go...it’s just the 404 header bugging me.

                      When i send my script to an empty page (so i can still use my own PHP coded
                      AJAX file) it still doesn’t work (but it does still return the JSON string
                      i need)

                      [edit]
                      This really is strange behavior, i have some code in an external file
                      that is included in a snippet. When i END the external file with a $modx->sendForward()
                      that is SUCCESSFUL it still displays the 404 header. I get my JSON string
                      and also the content from the ModX sendforward page, but still a 404 header.
                      Am i doing something terribly wrong, or is this not right?
                      [/edit]
                        Follow me on twitter: @b03tz
                        Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
                        CodeMaster