使用 onMissingTemplate 代替存根 cfm 文件
在我们的 ColdFusion 应用程序中,每个请求都会经过 index.cfm
Application.cfc 决定组成用户实际需要的查询和表单参数。这些组件被实例化,内容通过 OnRequestStart 被删除。
对于简单的情况,我们不想总是使用查询/表单参数来命中index.cfm,而是希望命中“缺失”的cfm(即MyApp.cfm)并允许OnMissingTemplate函数解析出我们真正想要的内容这一事实一个组件(即 MyApp)。
另一种方法是实际上将 cfm 存根文件放入组件的“通用”调用中,但似乎使用 OnMissingTemplate 我们不需要这样做。
这是 OnMissingTemplate 的合理用途吗?
In our ColdFusion application each request goes through index.cfm
Application.cfc decides form the query and form parameters which componetes the user is actually wanted. Those components are instantiated and the content is dropped through OnRequestStart.
Rather than always hit index.cfm with a query/form parameter, for simple cases, we would like to hit a "missing" cfm (i.e. MyApp.cfm) and allow the OnMissingTemplate function parse out the fact that we really want the content of a component (i.e. MyApp).
Another way to do this would be to actualy put cfm stub files in for "generic" calls to the components but it seems like with OnMissingTemplate we do not need to do that.
Is this a reasonable use for OnMissingTemplate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 onMissingTemplate 的一个很好的用途。只需确保如果您使用的是 IIS,则确保链接到的文件实际上是 .cfm (MyApp.cfm) 文件,而不是目录 (/MyApp/)。有关详细信息,请参阅以下链接:
http://www.bennadel.com/blog/1625-ColdFusion-8-s-OnMissingTemplate-So-Close-To-Being-Good.htm
http://www.bennadel.com/blog/1694-ColdFusion- s-OnMissingTemplate-Event-Handler-Works-With-CFC-Requests.htm
That's a great use for onMissingTemplate. Just make sure that if you're using IIS, that you make sure that the files you're linking to are actually .cfm (MyApp.cfm) files, and not directories (/MyApp/). See these links for more information:
http://www.bennadel.com/blog/1625-ColdFusion-8-s-OnMissingTemplate-So-Close-To-Being-Good.htm
http://www.bennadel.com/blog/1694-ColdFusion-s-OnMissingTemplate-Event-Handler-Works-With-CFC-Requests.htm