Changing from a dynamic root to a directory

34 views
Skip to first unread message

Mike

unread,
Apr 15, 2013, 11:09:43 AM4/15/13
to col...@googlegroups.com
I was just told something I was doing was not necessarily going to be an option so I have to ask this question.  Examples and instructions don't exactly seem to be doing what I was expecting, but I might be assuming too much.

Typically I create a website my creating a directory in my web root, dumping the code there, CF mapping /coldbox to wherever I have CB installed then creating a local host record (and apache vm host) to that directory so I can not only use something like DEV.MYSITE.COM to get to the site, but also so that I can ALWAYS treat everything as if it is in the root.

But I'm told the server I am going to publish to may not give me that option (don't ask) so I want to be able to NOW do something like LOCALHOST/MYSITE.  Changing NOTHING, if I do that, I get an error saying that it cannot find my path "model.someservice"...which I assume because really it needs to be "mysite.model.someservice" (which tested, works)...but obviously I don't want to have to go and change all my code that already exists.

I expected to be able to change one or two special variables in application.cfc, but both tests failed.

what am I missing?

Mike Craig

Andrew Scott

unread,
Apr 15, 2013, 11:48:09 AM4/15/13
to col...@googlegroups.com
Mike, it is never good practice to put sites into the webroot like this. If the webroot is ever hacked then they get access to every single site in the directory.

I always do this in development.

myprojects/myProject


Then each new project is added to the myProjects folder, but myProjects is never web accessible. There will not be 1 hosting provider that will do this any other way.

So with that out of the way, what is it that your actually trying to do with your method?


Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/





--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mike Craig

unread,
Apr 15, 2013, 1:13:31 PM4/15/13
to col...@googlegroups.com
I don't think it matters how many directories deep you want to go...I just cannot get a directory to "behave" as the root of my site.  All I know is regardless of where I put it, if I use a host entry to treat that directory as the root of my site, my "normal way" of doing things, dev.mysite.com works fine but localhost/mysite does not so I assumed 

<cfset COLDBOX_APP_ROOT_PATH = getDirectoryFromPath(getCurrentTemplatePath())>
<cfset COLDBOX_APP_MAPPING   = "">

one of those two settings would have to change but nothing I change seems to make any difference.  If I append the first with "/mysite" I cannot see the configuration file, if I add "/mysite" to the latter, the cb pathing to classes does not work but what I don't want to do is change my pathing to "mysite.model.xxxx" because if I move it...well, I'm sure you can see how that would not be preferrable.

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77


br...@bradwood.com

unread,
Apr 15, 2013, 1:23:55 PM4/15/13
to col...@googlegroups.com
You shouldn't need to change either of those settings as they are auto-detected unless you are going to be using remote proxies or Flex gateways.

Regarding your model paths, a ColdFusion mapping should help fix that.  Depending on how you're using WireBox, scan locations and directory mappings are already essentially relative.

Can you elaborate on what errors you are receiving when you try to run your app in a sub directory?  There should be a coldbox setting called "appMapping" automatically created for you which can also be helped to make other settings dynamic.  Just keep in mind that appMapping will be an empty string if your app is in the web root.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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


--------- Original Message ---------
Subject: Re: [coldbox:18049] Changing from a dynamic root to a directory
From: Mike Craig <mi...@terradotta.com>
Date: 4/15/13 12:13 pm
To: col...@googlegroups.com

I don't think it matters how many directories deep you want to go...I just cannot get a directory to "behave" as the root of my site.  All I know is regardless of where I put it, if I use a host entry to treat that directory as the root of my site, my "normal way" of doing things, dev.mysite.comworks fine but localhost/mysite does not so I assumed 

Mike Craig

unread,
Apr 15, 2013, 1:36:40 PM4/15/13
to col...@googlegroups.com
ok...removed any customizations of those settings.

"localhost" is my webserver and that points to c:/sites

/tdcc is now a directory under c:/sites

I copy all the code into c:/sites/tdcc

I access the site via "localhost/tdcc/index.cfm"

I get

  Could not find the ColdFusion component or interface

  model.basecollector.

    Ensure that the name is correct and that the component or interface exists.

At this point I am assuming this is getting hit on the first wirebox mapping

  map("Glyphs").to("model.system.GlyphCollection").asSingleton().asEagerInit();

which is defined as

component extends="model.basecollector" accessors="true" singleton {
property name="injector" inject="wirebox";
property name="dao" inject="tdcc.model.system.TDCCModuleIntegrationDAO";
property name="moduleservice" inject="coldbox:moduleService";
property name="loaded" type="boolean";
TDCCModuleIntegrationService function init() {
this.setLoaded(false);
this.setData({});
return this;
};

}

when the site was being aliased by vmhosts and accessed as hosted site, this error does not occur.  If I change the model. references to tdcc.model., it works and then fails on the next class being wireboxed.

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




br...@bradwood.com

unread,
Apr 15, 2013, 1:47:52 PM4/15/13
to col...@googlegroups.com
Yep. that would be correct.  You'll need to create a mapping for "model" so ColdFusion knows how to resolve it.  If you have multiple sites, I'd recommend an app-specific mapping.

Your other option is to append the appMapping setting as a prefix to all your bindings.  

Mike Craig

unread,
Apr 15, 2013, 1:58:32 PM4/15/13
to col...@googlegroups.com
So I assume

     property name="dao" inject="model.system.TDCCModuleIntegrationDAO";

is not going to be an option unless I map "model" to "/tdcc/model" (or wirebox everything) since I cannot use variables...and then I'll have a problem with...

     component extends="model.basecollector" accessors="true" singleton {

because I cannot use a variable in the extend attribute?

Also, if I map "model", I assume I'd have to map other directories like interceptor?

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Mike Craig

unread,
Apr 15, 2013, 2:09:31 PM4/15/13
to col...@googlegroups.com
I added 

<cfset this.mappings[ "/model" ] = getDirectoryFromPath(getCurrentTemplatePath()) & "/model/" />

and got past the model problem, the site comes up...but I have not tested interceptors for the same problem and cannot tell if my modules loaded (I think they did) because the CB debugging panes are now not showing up

groan...why would anyone do this this way :(

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Jason Durham

unread,
Apr 15, 2013, 2:09:35 PM4/15/13
to col...@googlegroups.com
I typically create an appRoot mapping in App.cfc when my Coldbox code lives outside of the webroot.  

inject="appRoot.model.system.TDCCModuleIntegrationDAO" 

component extends="appRoot.model.basecollector" accessors="true" singleton {





Jason Durham

Mike Craig

unread,
Apr 15, 2013, 2:12:35 PM4/15/13
to col...@googlegroups.com
oooh...that had never occured Jason..I like that...so now you can do the same for any CB path and if you moved to another sub-directory you just change the mapping or if you created a virtual host to make it a root site, you could set appRoot to map to "/".

Thanks!

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Mike Craig

unread,
Apr 15, 2013, 2:17:39 PM4/15/13
to col...@googlegroups.com
perfect so far...except the CB debug panels are still not showing up...otherwise, interceptors, models, modules all seem to work correctly with a minimum amount of change.

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Mike Craig

unread,
Apr 15, 2013, 2:21:20 PM4/15/13
to col...@googlegroups.com
Never mind about the debugger...rogue abort.

So now, with that setting in there, I can actually use "dev.tdcc.com" or "localhost/tdcc/index.cfm" and both work swimmingly.

Thanks Andrew, Brad and Jason for getting me on the path!

heh...pun was unintentional

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Craig

unread,
Apr 16, 2013, 10:49:19 AM4/16/13
to col...@googlegroups.com
I maybe misunderstanding the situation, but coldBox handles mapping concept for you!

When I'm using inject="" or getmodel(""), the model directory is not explicitly typed, because coldbox's model look up routine includes the model directory.

for example, if my directory structure is

/ ->webroot
/myCBApp
/myCBApp/model
/myCBApp/model/forum
/myCBApp/model/forum/forumService.cfc
/myCBApp/model/forum/forumDAO.cfc
/myCBApp/model/forum/forumDTO.cfc
/myCBApp/views
/myCBApp/handlers
/myCBApp/handlers/general.cfc
/myCBApp/modules
/myCBApp/modules/myCBModule
/myCBApp/modules/myCBModule/model
/myCBApp/modules/myCBModule/model/auth
/myCBApp/modules/myCBModule/model/auth/loginService.cfc

then in my handler (general.cfc) I write the following and coldBox will find it
     local.oService = GetModel("forum.forumService");
        or
     local.oService = GetModel("auth.loginService");

also when i'm injecting, i do not use the "model" directory
     <cfproperty name="oDAO" inject="forum.forumDAO" scope="instance" />



And for the links that get built, i use coldBox's appMapping configuration and the function event.buildLink("link to build")


The only time the above is an issue is when a module has the exact same "model" path as another module or parent application.  Therefore, I have started including my own DSLBuilder configuration in every module to force a naming space convention, to eliminate any future conflicts.

so in my above example, i originally had 
local.oService = GetModel("auth.loginService");

and now I reference that by
local.oService = GetModel(dsl="myCBModule:auth.loginService");


I hope this helps and doesn't confuse the situation.
Craig

Mike Craig

unread,
Apr 16, 2013, 11:10:11 AM4/16/13
to col...@googlegroups.com
Not at all...and after reading it I got horribly excited...so being early enough in the process I thought I'd give it a try but I immediately but for some reason, this magic does not work for me.  I immediately get an error that components are not available.  I wonder why?

Mike

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Mike Craig

unread,
Apr 16, 2013, 11:16:02 AM4/16/13
to col...@googlegroups.com
but man would I love for that to work

MIKE CRAIG  |  SENIOR DEVELOPER
TERRA DOTTA, LLC  |  501 W FRANKLIN ST, STE 105, CHAPEL HILL, NC 27516  |  877.DOTTA.77




Reply all
Reply to author
Forward
0 new messages