收录日期:2019/10/18 22:09:31 时间:2010-06-07 14:04:33 标签:coldfusion,cflogin

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.

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>

and call like:

logout();

Obviously, this is a trivial example. You'd want to specify your arguments, your return value, etc. in your actual code.

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.

as a side note, there is a small effort going on over at CFLib.org to create functions for all CF Tags. check out CFMLLib for more details