1

It's possible with coldfusion convert this php code?

if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ){

    //do something...

}

I have tried something as:

if( structKeyExists( url , "bSortable_[iSortCol_[#i#]]" ) ) {

}

But seems not working....probably I should try another way to make this?

The variables are two:

bSortable_1 = true;
iSortCol_1 = 1; 

I should obtain bSortable_1 value....

Tropicalista
  • 3,097
  • 12
  • 44
  • 72

2 Answers2

1

I am not much familiar with PHP but it seems that you are passing bSortable_1, iSortCol_1 kind of query variable to make sorting of table. I guess below code should work foe you.

<cfset url.bSortable_1 = 1>
<cfset url.iSortCol_1 = 1>
<!--- Option 1 --->
<cfif structKeyExists(URL,"bSortable_#URL.iSortCol_1#")>
    <cfoutput>Exists</cfoutput>
</cfif>

<!--- Option 2 --->
<cfset i = 1>
<cfif URL['bSortable_#URL['iSortCol_#i#']#']>
    <cfoutput>Exists</cfoutput>
</cfif>

Although I found this is so complex. I will suggest go for some nicer option.

Pritesh Patel
  • 1,969
  • 1
  • 18
  • 32
  • 1
    URL['bSortable_#URL['iSortCol_#i#']#'] will return value – Pritesh Patel May 24 '13 at 03:52
  • The answer is ok. Pritesh comment add more insight...I'm trying to create a server side logic for DataTables plugin... – Tropicalista May 24 '13 at 03:58
  • http://stackoverflow.com/questions/16920589/iteration-through-url-request-collection-variables-by-dynamic-evaluation my datatables , same question, different way to achiece using cfscript – Jay Rizzi Jun 05 '13 at 00:33
1

This is explanation requested in the comments. There are at least two url variables available, bSortable_1 and iSortCol_1. Both the php code and Pritesh's answer have this sort of structure.

<cfif somethingabout_bSortable_1.somethingabout_iSortCol_1>
do something

By treating the variables separately, my structure would resemble this:

<cfif somethingabout_bSortable_1 and (or or) somethingabout_iSortCol_1>
do something

Going to the StructkeyExists function, but with static values, it would be this

<cfif StructKeyExists(url, "bSortable_1") and StructKeyExists(url, "iSortCol_1")>
do something

For dynamic values, I don't know what would work so I would have to find out. Having said that, the first thing I'd try is:

<cfloop from = "1" to = SomeMaximum index = "i">
<cfif StructKeyExists(url, "bSortable_#i#") and StructKeyExists(url, "iSortCol_#i#")>
do something
closing tags
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43