Link to home
Start Free TrialLog in
Avatar of xeondxb
xeondxbFlag for United Arab Emirates

asked on

IF Condition Not Showing Right Result...

Hi,

Im trying to checking if “ query_string” is not coming  or if it is NULL AND template is NOT “Index.cfm ” forward  to ERROR.CFM Page
Im doing to prevent error if someone remove IDs or remove query string
When im writing this code my index.cfm page is also not coming it going on error.cfm page other then this everything working fine.


Here is my index.cfm code.
<cfset currTempl = trim(GetFileFromPath(GetCurrentTemplatePath()))>
Here im checking current template name .

Application.cfc code:
<cfparam name="indexTemp" default="False" type="boolean">
<cfparam name="currTempl" type="string" default="">

<cfif trim(currTempl) EQ "INDEX.CFM" OR trim(currTempl) EQ "index.cfm" >
<cfset indexTemp = True >
</cfif>


<cfif len(trim(QUERY_STRING)) IS 0 AND indexTemp NEQ True >
<cflocation url="error.cfm" addtoken="yes">
</cfif>

If there is any easy way please let me know, really appreciated
Avatar of _agx_
_agx_
Flag of United States of America image

The only thing I see wrong is a missing CGI scope in from of QUERY_STRING.  This works correctly for me:

<cfset currentTemplate = trim(GetFileFromPath(GetCurrentTemplatePath()))>
<!--- by default, CF string comparisons are case insensitive --->
<cfif currentTemplate neq "index.cfm" AND not len(trim(CGI.QUERY_STRING))>
      go to error page
<cfelse>
      okay
</cfif>

EDIT  But if you're calling it from Application.cfc in one of the request methods you should use the "targetPage" argument instead of currentTemplate (because it returns Application.cfc not the requested page).  Example:

      <cffunction name="onRequestStart" returnType="void">
               <cfargument name="targetPage" type="string" required="true" />
      
            <cfset currentTemplate = trim(GetFileFromPath(arguments.targetPage))>
            <!--- by default, CF string comparisons are case insensitive --->
            <cfif currentTemplate neq "index.cfm" AND not len(trim(CGI.QUERY_STRING))>
                  <cflocation url="error.cfm">
            </cfif>      
      </cffunction>
Avatar of xeondxb

ASKER

yea it working now im facing only one issue
when it is going on error.cfm  it is not showing because there is no queryString
AND not len(trim(CGI.QUERY_STRING))>
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xeondxb

ASKER

Thanks Man.....
Sorry, I know zip about Dreamweaver.  As far as cfc's, can you update your question to be more specific about what you're ultimately trying to do? The basic concept of getters/setters is very simple. But whether you even need cfc's, or how you structure them, depends on your app's needs.
Avatar of xeondxb

ASKER

i just updated the question could you have a look ....

--------------------------------------------------------------------------
Hi dear,

i know coldfusion when it was not OOP but know, im  reading coldfusion 9 in this version i can  use OOP, ORM i was writing some exmpale code, i just want to understand how does this getter and setters works where we can use? how does it work when we  get data from database.

about dreamweaver CS6 how can i configure it to work like coldfusion builder because i saw CFBuilder it is easy to work with, like a .NET Studio and we can also save lot of  time to writing code. i don't have CF-Builder software.

i was reading CF-Builder can auto generate  CFC components  like Gateway.cfc, service.cfc and DAO.cfc
That's a lot of questions for one thread ;-) Unfortunately I don't use ORM either. Here are the parts I can answer:

    about dreamweaver CS6 how can i configure it to work like coldfusion builder

CF Builder is specifically designed for CFML. So it has create CFC wizards built into the app. IIRC, Dreamweaver isn't specifically designed for CF. So it's quite possible it doesn't include (or doesn't support) those wizards. You'd have to ask someone who knows Dreamweaver well.

http://blogs.adobe.com/cfbuilder/2009/07/orm_cfc_generator_1.html


    i don't have CF-Builder software.

If you want to try it out, I hear there's an Express version. They say it is full featured for 60-days, then drops down to a limited version.

Best of luck!
Avatar of xeondxb

ASKER

thanks man ... your great...