Application.cfc
Application.cfcは必ず最初に実行される。
どのコードをどのタイミングで実行するのか指定できる。今回はonRequestStart
このタイミングでrequest.nameにhogeを入れる。
demo.htmlでrequest.nameを使うことができるし、ほかのhtmlでも共有して使うことができる。
普通はsessionとかcookieとかの記録をする。
注意:ファイル名のAは必ず大文字で。
コード
demo.html
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<cfoutput>#request.name#</cfoutput>
</body>
</html>
Application.cfc その①
<cfcomponent>
<!---application名以外はデフォルト--->
<cfset This.name = "MyApp">
<!---cfmページが呼ばれたときに最初に必ず--->
<cffunction name="onRequestStart">
<cfset request.name = "hoge">
</cffunction>
</cfcomponent>
Application.cfc その②
component {
this.name = "MyApp";
public void function onRequestStart() {
var request.name = "taro";
}
}
参考
http://coldfusion.blog.shinobi.jp/coldfusionのタグ/application.cfcでエラー処理