Coldfusion 8:IsDefined(“URL.variable”) 并且不是“”?

发布于 2024-10-01 23:53:00 字数 156 浏览 1 评论 0原文

我试图找出 url 变量是否存在,如果不存在,请确保它不为空。

这不起作用:

<cfif IsDefined('URL.affiliateId') and is not "">
    //
</cfif>

I'm trying to find out if a url variable exists, and if it doesn't, make sure that it's not empty.

This does not work:

<cfif IsDefined('URL.affiliateId') and is not "">
    //
</cfif>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我恋#小黄人 2024-10-08 23:53:00
<cfif structKeyExists(url, 'affiliateID') and trim(url.affiliateID) neq "">...</cfif>
<cfif structKeyExists(url, 'affiliateID') and trim(url.affiliateID) neq "">...</cfif>
被翻牌 2024-10-08 23:53:00

您还可以使用来简化逻辑。以确保 URL 变量始终存在。那么您不需要 2 个条件,而只需要 1 个。

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif trim( URL.affiliateId ) is not "">
     do stuff here
</cfif>

You can simplify the logic a bit as well by using <cfparam> to ensure that the URL variable always exists. Then rather than having 2 conditions, you just need 1.

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif trim( URL.affiliateId ) is not "">
     do stuff here
</cfif>
起风了 2024-10-08 23:53:00

忽略大部分空白

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId))>
    value is defined and not empty
</cfif>

...或者交替

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId)) gt 0>
    value is defined and not empty
</cfif>

To ignore most white space

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId))>
    value is defined and not empty
</cfif>

... or alternately

<cfif IsDefined('URL.affiliateId') and len(trim(URL.affiliateId)) gt 0>
    value is defined and not empty
</cfif>
栀梦 2024-10-08 23:53:00
<cfif IsDefined('URL.affiliateId') and URL.affiliateId neq "">
    //
</cfif>
<cfif IsDefined('URL.affiliateId') and URL.affiliateId neq "">
    //
</cfif>
空城缀染半城烟沙 2024-10-08 23:53:00

我将总结答案并提供我的版本:

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif len(trim(URL.affiliateId))>
     ...do something with the affiliate...
</cfif>

您不需要 structKeyExists 或 isDefined,最好避免它们。此外,您不需要“len()”之后的“大于零”部分。

I will just sum up the answers and offer my version of it:

<cfparam name="URL.affiliateId" type="string" default="" />

<cfif len(trim(URL.affiliateId))>
     ...do something with the affiliate...
</cfif>

You do not need structKeyExists or isDefined and it would be better to avoid them. Also you do not need the 'greater than zero' part after the 'len()'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文