cfscript中的cflogin [英] cflogin in cfscript
问题描述
我正在尝试学习新的cfscript语法,并使用cflogin。
我猜想我不能在cfscript中混合cf标签,并且看不到与cflogin,cflogout,cfloginuser等效的脚本。
I'm trying to learn the new cfscript syntax, as well as use cflogin. I'm guessing I can't mix cf tags in cfscript, and I don't see a script equivalent to cflogin, cflogout, cfloginuser.
应该我调用以CF8语法编写的组件以便使用cflogin?
Should I call a component that is written in the CF8 syntax in order to use cflogin?
public void function onRequest(required string Page) output="true" {
if (StructKeyExists(url,"logout")) {
<cflogout>
}
<cflogin>
local.qryUsr = new Components.Usr.Login(form);
if (local.qryUsr.Recordcount) {
<cfloginuser name="#form.UsrName#" password="#form.UsrPassword#" roles="#local.qryUsr.Roles#">
} else {
request.errorMessage = "Incorrect login";
include login/login.cfm;
return;
}
</cflogin>
include arguments.Page;
}
推荐答案
您不能直接混合标签和脚本。但是,您可以通过在标签周围编写函数包装程序来伪造它:
You cannot directly mix tags and scripts. However, you can fake it by writing function wrappers around the tags:
<cffunction name="logout">
<cflogout />
</cffunction>
并像这样调用:
logout();
很明显,这是一个简单的例子。您需要在实际代码中指定参数,返回值等。
Obviously, this is a trivial example. You'd want to specify your arguments, your return value, etc. in your actual code.
注一:请勿对接受用户输入的通用查询函数执行此操作,因为您将无法使用cfqueryparam。
Note one: Do not do this for a generic query function that accepts user input, as you won't be able to use cfqueryparam.
注意二:我通常不这样做。如果我要编写仅依赖标记操作的代码,请使用标记语法。
Note two: I generally don't do this. If I'm writing code that depends on tag-only operations, I use the tag syntax.
这篇关于cfscript中的cflogin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!