代码之家  ›  专栏  ›  技术社区  ›  dcolumbus

Coldfusion 8:已定义('URL.variable'),但不是“”?

  •  6
  • dcolumbus  · 技术社区  · 15 年前

    这不起作用:

    <cfif IsDefined('URL.affiliateId') and is not "">
        //
    </cfif>
    
    5 回复  |  直到 15 年前
        1
  •  15
  •   scrittler    15 年前
    <cfif structKeyExists(url, 'affiliateID') and trim(url.affiliateID) neq "">...</cfif>
    
        2
  •  4
  •   charliegriefer    15 年前

    您可以通过使用& lt;CFPARAM.GT来简化逻辑,以确保URL变量始终存在。那么你只需要1个而不是2个条件。

    <cfparam name="URL.affiliateId" type="string" default="" />
    
    <cfif trim( URL.affiliateId ) is not "">
         do stuff here
    </cfif>
        3
  •  1
  •   Leigh josh poley    15 年前

    忽略大部分空白

    <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>
    
        4
  •  0
  •   Harrison    15 年前
    <cfif IsDefined('URL.affiliateId') and URL.affiliateId neq "">
        //
    </cfif>
    
        5
  •  0
  •   Uphill_ What '1    15 年前

    <cfparam name="URL.affiliateId" type="string" default="" />
    
    <cfif len(trim(URL.affiliateId))>
         ...do something with the affiliate...
    </cfif>
    

    你不需要StrutKy存在或者被定义,最好避免它们。此外,在“len()”之后不需要“大于零”部分。