cflogin in cfscript

我是研究僧i 提交于 2019-12-24 17:12:25

问题


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;
}

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1712223/cflogin-in-cfscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!