Reading the Adobe doc on onMissingTemplate(), it s...
# cfml-general
j
Reading the Adobe doc on onMissingTemplate(), it says to use an include, something like
include application.urls.404
instead of relocating to another page ala
location(url=application.urls.404, addToken=false)
Why is the include the "right" way and the relocate the "wrong" way?
d
Include hides/protects the 404 template
a
Because cflocation sends a 302 (or a 301? Can't remember); you want to return a 404
cflocation says "go to this other URL", which is not the right response when it's the current URL you wanna say "nope, the document at this URL don't exist"
d
Include stays on the missing Url/location But Adam’s explanation is better
It’s an opinion. Not right or wrong
a
Returning a 3xx in a 4xx situation is wrong. There's no opinion going on here 😉 One can choose to do it wrong - sure, knock yerself out - but it's still wrong.
🤣 1
👍 3
j
so maybe something like:`public boolean function onMissingTemplate(required string targetPage) {`
cfheader(statuscode = "404", statusText = "file not found");
include application.urls.404;
return true;
}
1
d
Doesn't onMissingTemplate fire when cf tries to cfinclude or cfmodule to file file that doesn't exist, not just when you navigate there directly? I wouldn't think 404 is right in that case, should be 500.
Not sure if it also fires if you try to call a method of a cfc that doesn't exist.
a
It's poorly named. It's a 404 handler, not a missing file handler
d
so it doesn't fie on missing includes etc? memory aint what it used to be, if it ever was.
a
I had to check 😉 And no, it doesn't fire if the top-level file is there (eg: the
woo.cfm
in
<http://example.com/woo.cfm>
), but then
woo.cfm
includes a file that doesn't exist. It only fires if
woo.cfm
doesn't exist.
d
404 handler, you're right.
j
@Adam Cameron thank you. Inherited a very legacy app (cue Jeff Goldblum "thats a big pile" meme) when a colleague retired. Trying to use the app cfc file in a better way to handle lifecycle events in the thing. Been on the DB, data, and reporting side of things for a while, so trying to get spun back up on CF.
👍 1