Hey All,
It’s been a while but I just got asked to help work on a large project redesigning the intranet for the Fish and Wildlife Service and we are using ColdBox 2.6.3.
I am trying to setup environment control since we are using svn and have development versions of the application in various branches and then a staging version in the trunk. In the Coldbox config I have added the following interceptor definition at the top of the interceptor definitions (tested both fireOnInit=true and false):
config/environments.xml.cfm
true
Then I have the following environments in the config:
If I hit the page on our dev server for Jon’s branch (http://server.com/ver/branches/jon) it is still loading the AppMapping value that is set in the main coldbox config (identical to the trunk environment). For instnce, #buildLink(‘blog’)# returns http://server.com/ver/trunk/index.cfm/blog
Can the Environment Control Interceptor be used to override the AppMapping setting defined in the coldbox config? If so, why would it not be working?
Thanks for your help!!!
-Aaron
OK, I was having a brain fart. Of coarse CGI.HTTP_HOST is not going to detect /jon/ in the url. So what I need to do is override the DetectEnvironment method and set it to part the CGI.SCRIPT_NAME instead. I see that this can be done (http://ortus.svnrepository.com/coldbox/trac.cgi/wiki/cbEnvironmentControl#ExtendingTheInterceptor) but not how.
How do I override that method?
Ok, I almost forgot what OOP is and how to override methods. LOL. So this is what I did.
I created an EnvironmentControl component in my interceptors folder that extends the coldbox EnvironmentControl interceptor:
for(i=1; i lte ArrayLen(arguments.environmentsArray); i=i+1){
if ( listFindNoCase(trim(arguments.environmentsArray[i].XMLAttributes.urls),cgi.script_name) ){
//Place the ENVIRONMENT on the settings structure.
setSetting("ENVIRONMENT", trim(arguments.environmentsArray[i].XMLAttributes.name));
return trim(arguments.environmentsArray[i].XMLAttributes.name);
break;
}
}
return "";
Then in the config I define the EnvironmentControl interceptor to look for my version:
config/environments.xml.cfm
true
Which is almost acceptable except that now I have to change the path to the interceptor class in the config for each environment. The path “/ver/branches/jon/” is going to have to be changed before committed to the trunk for staging.
Is there a way to make it so that I don’t have hard code the path to my custom EnvironmentControl interceptor?
Thanks,
Aaron
Man. It’s still not working! How can I change the detectEnvironment method so that behaves the same as the original except instead of being based on CGI.HTTP_HOST it is based on CGI.SCRIPT_NAME? I thought changing that below would work but its not:
This is what I ended up coming up with:
for(i=1; i lte ArrayLen(arguments.environmentsArray); i=i+1){
list=trim(arguments.environmentsArray[i].XMLAttributes.urls);
for(j=1; j lte listlen(list); j=j+1){
url=listGetAt(list,j);
name=trim(arguments.environmentsArray[i].XMLAttributes.name);
if (cgi.script_name CONTAINS url){
//Place the ENVIRONMENT on the settings structure.
setSetting("ENVIRONMENT", name);
return name;
break;
}
}
}
return "";
It appears to work!