Re: How do I solve this path issue for components?
There are a lot of different ways to solve this problem, but here are a couple. 1. Use a variable to denote your CFC root. For instance, you could set request.pathRoot or something. So in development you'd have request.pathRoot = mySite-dev; and in production it would be request.pathRoot = mySite. Then when you create an object, do something like myComponent = createObject(component, #request.pathRoot#.myComponent); 2. Use a factory object, or a façade, or whatever you want to call it, to create your other objects. You still have to create your façade object, but for example, you could have request.facade with a function like returnObject() or something like that. Then in your code you'd do myComponent = request.facade.returnObject(myComponent); There are lots of frameworks that essentially do this in more complicated fashions, but by doing something like this you aren't leaving all the code across your site reliant on the existence of request.pathRoot. You can keep the logic for where your components are located in just Application.cfc and Facade.cfc (or wherever). This isn't really a factory or a façade, per se, but I'm not really sure what the best term would be. You can learn as much about Inversion of Control (I'm explaining a simplified version of it in #2) by checking out the ColdBox or ColdSpring frameworks. - Andrew. On 2010-06-08, at 16:03, Rick Faircloth wrote: Hi, all. I've started using two different folders on my servers for each site. The first is for viewing a site online during development and the second folder is for production. That is creating path issues with my component path notation. If a path is on the index.cfm in the root of a site, I can use: components.myComponent The path above works for both development and production sites since the component directory is always directly under the root. However, on all other pages, such as .cfm pages within a cfm directory, I have been just specifying my webroot in the path to make it work: mySite.components.myComponent But with different root directories for development and production, that won't work. Locally, I have this directory structure: (Typically, I just mirror this structure on my production site, so there haven't been any problems) mySite.components.myComponent However, now I'm using SVN to automatically FTP changes on commit to the following structure for the development version of the site: mySite-dev.components.myComponent On my server, the production site is under: mySite.components.myComponent So, I have two sites online that I need to use depending on whether I want to publish to the development version or the production version. How can I work my paths so they function under each situation? Thanks! Rick ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334373 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: How do I solve this path issue for components?
Why not use per-application mappings? In Application.cfc, you can set this.mappings[ '/mysite' ] to either the production or dev CFC root as needed... On Tue, Jun 8, 2010 at 1:03 PM, Rick Faircloth r...@whitestonemedia.com wrote: Hi, all. I've started using two different folders on my servers for each site. The first is for viewing a site online during development and the second folder is for production. That is creating path issues with my component path notation. If a path is on the index.cfm in the root of a site, I can use: components.myComponent The path above works for both development and production sites since the component directory is always directly under the root. However, on all other pages, such as .cfm pages within a cfm directory, I have been just specifying my webroot in the path to make it work: mySite.components.myComponent But with different root directories for development and production, that won't work. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334374 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: How do I solve this path issue for components?
+1 for per-application mappings. You can even get fancy and set it it based on cgi.server_name or path_info so you don't have to change the code between dev and production. Note, for this to work, dev and production need to be in their OWN application. A better solution would be to actually have a dedicated box for your dev server so you can do testing there without fear of ruining your production server's stability. There are also settings I enable on a production server like Trusted Cache that you wouldn't be able to use for a dev server. If you can't spare a separate box, AT LEAST create different sites for dev and production on your server with their own completely separate web root. www.mysite.com and devwww.mysite.com. If you are running CF Enterprise in multi-server mode you can actually have separate instances for dev and production which is the next best thing to a different physical server. Ok, actually a VM is the next best thing to that, but I digress... ~Brad Original Message Subject: Re: How do I solve this path issue for components? From: Sean Corfield seancorfi...@gmail.com Date: Tue, June 08, 2010 3:34 pm To: cf-talk cf-talk@houseoffusion.com Why not use per-application mappings? In Application.cfc, you can set this.mappings[ '/mysite' ] to either the production or dev CFC root as needed... On Tue, Jun 8, 2010 at 1:03 PM, Rick Faircloth r...@whitestonemedia.com wrote: Hi, all. I've started using two different folders on my servers for each site. The first is for viewing a site online during development and the second folder is for production. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334375 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: How do I solve this path issue for components?
Thanks, Andrew... I'll have a go at some of that! Rick -Original Message- From: Andrew Clarke [mailto:s...@clarke.ca] Sent: Tuesday, June 08, 2010 4:16 PM To: cf-talk Subject: Re: How do I solve this path issue for components? There are a lot of different ways to solve this problem, but here are a couple. 1. Use a variable to denote your CFC root. For instance, you could set request.pathRoot or something. So in development you'd have request.pathRoot = mySite-dev; and in production it would be request.pathRoot = mySite. Then when you create an object, do something like myComponent = createObject(component, #request.pathRoot#.myComponent); 2. Use a factory object, or a façade, or whatever you want to call it, to create your other objects. You still have to create your façade object, but for example, you could have request.facade with a function like returnObject() or something like that. Then in your code you'd do myComponent = request.facade.returnObject(myComponent); There are lots of frameworks that essentially do this in more complicated fashions, but by doing something like this you aren't leaving all the code across your site reliant on the existence of request.pathRoot. You can keep the logic for where your components are located in just Application.cfc and Facade.cfc (or wherever). This isn't really a factory or a façade, per se, but I'm not really sure what the best term would be. You can learn as much about Inversion of Control (I'm explaining a simplified version of it in #2) by checking out the ColdBox or ColdSpring frameworks. - Andrew. On 2010-06-08, at 16:03, Rick Faircloth wrote: Hi, all. I've started using two different folders on my servers for each site. The first is for viewing a site online during development and the second folder is for production. That is creating path issues with my component path notation. If a path is on the index.cfm in the root of a site, I can use: components.myComponent The path above works for both development and production sites since the component directory is always directly under the root. However, on all other pages, such as .cfm pages within a cfm directory, I have been just specifying my webroot in the path to make it work: mySite.components.myComponent But with different root directories for development and production, that won't work. Locally, I have this directory structure: (Typically, I just mirror this structure on my production site, so there haven't been any problems) mySite.components.myComponent However, now I'm using SVN to automatically FTP changes on commit to the following structure for the development version of the site: mySite-dev.components.myComponent On my server, the production site is under: mySite.components.myComponent So, I have two sites online that I need to use depending on whether I want to publish to the development version or the production version. How can I work my paths so they function under each situation? Thanks! Rick ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334376 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: How do I solve this path issue for components?
Thanks for the tip, Brad... I decided to go with use of the cgi.server_name variable. Fast and easy. I just wanted to make sure some super-slick way of doing this hadn't come out lately. And, yes, the development and production sites are completely separate with their own webroot. So, unless I crash the server with something (which is not out of the realm of possibility) I should be ok. Two VPS's would be nice, but one's enough to pay for. :oP Rick -Original Message- From: b...@bradwood.com [mailto:b...@bradwood.com] Sent: Tuesday, June 08, 2010 4:46 PM To: cf-talk Subject: RE: How do I solve this path issue for components? +1 for per-application mappings. You can even get fancy and set it it based on cgi.server_name or path_info so you don't have to change the code between dev and production. Note, for this to work, dev and production need to be in their OWN application. A better solution would be to actually have a dedicated box for your dev server so you can do testing there without fear of ruining your production server's stability. There are also settings I enable on a production server like Trusted Cache that you wouldn't be able to use for a dev server. If you can't spare a separate box, AT LEAST create different sites for dev and production on your server with their own completely separate web root. www.mysite.com and devwww.mysite.com. If you are running CF Enterprise in multi-server mode you can actually have separate instances for dev and production which is the next best thing to a different physical server. Ok, actually a VM is the next best thing to that, but I digress... ~Brad ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334377 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
RE: How do I solve this path issue for components?
I'll probably go with the mappings on my next project, but for now I'll have to go with something like cgi.server_name. I've made the transition to application.cfc's instead of .cfm's, but for some reason, which I couldn't figure out after an entire day of trying, the application I'm working on was defining the wrong database. I couldn't figure out where is was coming from. It was happening during some (and *only* some) ajax transactions. Never could track it down even after stripping down the application.cfc. I finally just gave up and went to an application.cfm so I could get some work done. Perhaps after getting past the initial phase of development on this current site, I'll revisit the issue of the application.cfc defining the wrong database for the site. Weird... Rick -Original Message- From: Sean Corfield [mailto:seancorfi...@gmail.com] Sent: Tuesday, June 08, 2010 4:34 PM To: cf-talk Subject: Re: How do I solve this path issue for components? Why not use per-application mappings? In Application.cfc, you can set this.mappings[ '/mysite' ] to either the production or dev CFC root as needed... ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334378 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: How do I solve this path issue for components?
And, yes, the development and production sites are completely separate with their own webroot. So, unless I crash the server with something (which is not out of the realm of possibility) I should be ok. 0_0 ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:334379 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm