addRoute condition for custom route.

I"m trying to make

.com/pancho/services/web-design and
.com/anita/services/web-design and
.com/greg/services/web-design serve the same handler and function as

.com/services/web-design

My route is

addRoute(pattern=":designer?/:handler?/:action?");

the three designer urls work, but .com/services/web-design does not work because web-design is not a registered event. Designer name should be optional like a variable, but everything else is a normal route path handler/action/var1/var2 and so on.

In the Routes.cfm I think I can do something like:

addRoute(
pattern=":designer?/:handler?/:action?",
condition=function(requeststring){
thisPattern = listGetAt(requeststring,1,"/");
if (listfind(getSetting(“RegisteredHandlers”),thisPattern) neq 0) return true;
return false;
}
);
addRoute(pattern=":handler/:action?");

but I get an error which i think is misleading because the addRoute syntax looks good to me:

Error importing routes configuration file: Invalid construct: Either argument or name is missing. When using named parameters to a function, each parameter must have a name.

Ok, the condition argument is not in framework 3.5. So i’m using 3.7. But now I have to figure out why

# Function argument mismatch.
The getInstance function does not specify the same arguments or arguments in the same order in the coldbox.system.ioc.Injector ColdFusion component and the coldbox.system.ioc.IInjector ColdFusion interface.

The error occurred in D:\Websites\designersnetwork\coldbox\system\web\Controller.cfc: line 63
Called from D:\Websites\designersnetwork\coldbox\system\Coldbox.cfc: line 69
Called from D:\Websites\designersnetwork\coldbox\system\Coldbox.cfc: line 102
Called from D:\Websites\designersnetwork\coldbox\system\Coldbox.cfc: line 378
Called from D:\Websites\designersnetwork\Application.cfc: line 58 |

So haven’t been able to successfully install any of the 3.7 sample applications. I get the above error every time.

I"m running CF 9.0.1.274733, JAVA 1.6.0_17 and Coldbox 3.7

Do I need to patch CF with HotFix 4 and upgrade java to 1.7 in order to make 3.7 work. I can’t get passed this Function argument mismatch error.

I don’t think upgrading to Java 1.7 is going to fix that issue, I think if you look carefully you are trying to do a closure that I think only ColdFusion 10 is capable of doing here.

Daniel Mejia,

I would suggest that give a try with CF 9.0.2 , closure like methods do have problems in CF 9.0.1.

I’m pretty certain Andrew is correct and closures only work on CF10. You’ll have to find another way to do it. Can you declare the function above and just pass a reference to it?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks for the suggestion. I’ll be trying that after I successfully upgrade to 3.7. Doooh!

Coldbox 3.7.0 on CF 9.0.2

Hi guys,

I meant to get back to this post sooner. so I tested my route again. My CF Application log says

“Error”,“jrpp-11”, “12/10/13”, “14:43:01”,“351…”,“Error importing routes configuration file: Invalid construct: Either argument or name is missing. When using named parameters to a function, each parameter must have a name.”

I believe this is because 9.0.2 does not support closures like you guys mentioned already. But since I did not see anything about 3.7.0 requiring CF 10, then I thought that the condition closure is meant to work on my server.

Both of these routes are throwing the same error:

addRoute(pattern="/go/ff", response="<h1>Hello FireFox!</h1>", condition=function(requestString){
  return ( findnocase( "Firefox", cgi.HTTP_USER_AGENT ) ? true : false );
});

addRoute(
pattern=":designer?/:handler?/:action?",
condition=function(requeststring){
thisPattern = listGetAt(requeststring,1,"/");
if (listfind(getSetting(“RegisteredHandlers”),thisPattern) neq 0) return true;
return false;
}
);

Your confirmation is greatly appreciated.

If I do something like this it still fires the route:

addRoute(
pattern="/go/ff",
response=“

Hello FireFox!

”,
condition=false
);

since the condition equals false it should continue to the next added route.

Daniel,

That will be the reason…

Sorry I meant with the closures and 9.02, for your second problem with the condition. it is expecting a UDF or closure so it doesn’t consider false to be either of those.